2016-04-14 19 views
0

私のPythonのバージョンは3.5.1で、このコードを実行しようとしているhttps://developers.google.com/youtube/v3/code_samples/python#upload_a_video 時代遅れの印刷呼び出しを修正は、今では私にSyntaxErrorを与える:無効な構文エラーにユーチューブAPIのアップロードファイル:HttpError除いに無効な構文、電子

def resumable_upload(insert_request): 
    response = None 
    error = None 
    retry = 0 
    while response is None: 
    try: 
     print ("Uploading file...") 
     status, response = insert_request.next_chunk() 
     if 'id' in response: 
     print ("Video id '%s' was successfully uploaded." % (response['id'])) 
     else: 
     exit("The upload failed with an unexpected response: %s" % response) 

    except HttpError, e: //error here pointed at comma 

     if e.resp.status in RETRIABLE_STATUS_CODES: 
     error = "A retriable HTTP error %d occurred:\n%s" % (e.resp.status, 
                  e.content) 
     else: 
     raise 
    except RETRIABLE_EXCEPTIONS, e: 
     error = "A retriable error occurred: %s" % e 

    if error is not None: 
     print error 
     retry += 1 
     if retry > MAX_RETRIES: 
     exit("No longer attempting to retry.") 

     max_sleep = 2 ** retry 
     sleep_seconds = random.random() * max_sleep 
     print ("Sleeping %f seconds and then retrying..." % (sleep_seconds) 
     time.sleep(sleep_seconds) 

私は完全なpythonの初心者ですが、私は '試し'が欠けている可能性があることを尋ねましたが、そこにあります。私は、ライブラリサポートより新しいバージョンを持っているので、このためYouTube API v3 upload speeds

のパイソンをしようと

は、このエラーが発生することができますか? https://developers.google.com/api-client-library/python/start/installation?authuser=1

答えて

3

あなたが代わりにこのPythonの3

使用では動作しませんPythonの2構文、使用している:

except HttpError as e: 
+0

1最後の質問:time.sleep(sleep_secondsが)にSyntaxErrorを与える:無効にPython 3.5で変更された関数を読んだのですが、x秒間プログラムを待たせる新しい方法は何ですか? –

+1

問題は前の行にあります。あなたは 'print()'呼び出しのための閉じ括弧を持っていません。 –

関連する問題