2016-04-14 54 views
0

Benim piton sürümü bu kodu https://developers.google.com/youtube/v3/code_samples/python#upload_a_video Sabit eski baskı çağrıları çalıştırmaya çalışırken, 3.5.1, şimdi bana SyntaxError veriyor: geçersiz sözdizimi hatasıyoutube api yükleme dosyası: httpError hariç geçersiz sözdizimi, e

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) 

Ben python newbie tamamlıyorum, çünkü 'denemek', ama orada onun eksik olduğunu olabilir çünkü googled. Ben kütüphane desteklerden daha yeni bir sürümü var çünkü bu hata neden Can

çünkü bu YouTube API v3 upload speeds

ait piton çalışıyorsunuz? https://developers.google.com/api-client-library/python/start/installation?authuser=1

cevap

3

Sen Python yerine bu 3.

Kullanım çalışmaz Python 2 sözdizimi, kullandığınız:

except HttpError as e: 
+0

son bir soru: time.sleep (sleep_seconds) SyntaxError verir: geçersiz sözdizimi hatası ilk harf e işaret etti, python 3.5'de bu zaman işlevinin değiştiğini okudum, programın x saniye beklemesi için yeni bir yol ne olurdu? –

+1

Sorun, önceki satırda. Print() 'çağrısı için kapama paranteziniz yok. –