【问题标题】:Invalid syntax error in google python apigoogle python api中的无效语法错误
【发布时间】:2015-04-01 03:32:41
【问题描述】:

我是 google python api 客户端的新手。我正在向 https://developers.google.com/api-client-library/python/start/get_started.I 学习,想要制作一个将 python 对象转换为 JSON 数据并发送到 servlet 的 api。

文件api.py的python代码:

import os
import urllib2
import httplib2
import json
import requests
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run_flow
from oauth2client.file import Storage
from oauth2client import tools

api_version='1'
_file_="D:\API"


CLIENT_SECRETS = os.path.join(os.path.dirname(_file_))

flow=flow_from_clientsecrets(CLIENT_SECRETS,
  scope=[
      'https://www.googleapis.com/auth/devstorage.full_control',
      ],


http = httplib2.Http()
auth_http = credentials.authorize(http)

service=build('SendNotif',api_version,http=http)

req = urllib2.Request('http://example/notify')
req.add_header('Content-Type', 'application/json')

data={"message":"Hello User you are notified"}
data_json = json.dumps(data)

response = urllib2.urlopen(req, json.dumps(data))

显示的错误是:

    D:\API>python api.py
    File "api.py", line 25
    auth_http = credentials.authorize(http)
        ^
    SyntaxError: invalid syntax

请帮忙纠正我.. 提前谢谢....

【问题讨论】:

    标签: python-2.7 google-api-python-client google-app-engine-python


    【解决方案1】:

    您缺少此行的右括号:

    flow=flow_from_clientsecrets(CLIENT_SECRETS,
    

    【讨论】:

    • 现在它显示...` ile "D:\API\try.py",第 76 行,在 main(sys.argv) 文件 "D:\API\try.py ",第 62 行,在 main service = build(api_name,api_version,http=http) 文件 "D:\Python27\lib\site-packages\oauth2client\util.py",第 135 行,在 positional_wrapper 中返回包装(*args, **kwargs)文件“D:\Python27\lib\site-packages\googleapiclient\discovery.py”,第 202 行,在构建版本中))UnknownApiNameOrVersion:名称:发送版本:v1`
    • 阅读 developers.google.com.com/api-client-library/python/apis api 版本应该是 v1 或 v2,而不是 1。以供将来参考,如果您有其他问题,请将其作为新问题发布?
    猜你喜欢
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 2016-08-07
    • 2015-05-24
    相关资源
    最近更新 更多