2016-04-14 44 views
0

我的Python版本是3.5.1,試圖運行該代碼https://developers.google.com/youtube/v3/code_samples/python#upload_a_video 修正過時的打印通話,現在它給了我語法錯誤:無效的語法錯誤的YouTube 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) 

我是一個完整的蟒蛇新手,使用它可能是因爲我錯過了'嘗試',但它在那裏。

試圖蟒蛇正因爲如此YouTube API v3 upload speeds

可這一錯誤造成的,因爲我比庫支持更新的版本? https://developers.google.com/api-client-library/python/start/installation?authuser=1

回答

3

你使用Python語法2,不使用Python 3

使用此工作,而不是:

except HttpError as e: 
+0

最後一個問題:time.sleep(sleep_seconds)給出語法錯誤:無效在第一個字母e指向的語法錯誤,我讀過python 3.5中改變的時間函數,那麼什麼是使程序等待x秒的新方法? –

+1

問題在於上一行。 print()'調用沒有關閉圓括號。 –

相關問題