youtube api上传文件:除HttpError外的语法无效,e

时间:2016-04-14 21:18:35

标签: python youtube google-api youtube-api syntax-error

我的python版本是3.5.1,尝试运行此代码https://developers.google.com/youtube/v3/code_samples/python#upload_a_video 修复了过时的打印调用,现在它给了我SyntaxError:无效的语法错误

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

而尝试使用python

这个错误是否可以导致,因为我的版本比库支持的版本更新? https://developers.google.com/api-client-library/python/start/installation?authuser=1

1 个答案:

答案 0 :(得分:3)

您使用的是Python 2语法,它不能与Python 3一起使用。

请改用:

except HttpError as e: