Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Uber Rides Python SDK检索数据失败,错误为500_Python_Uber Api - Fatal编程技术网

使用Uber Rides Python SDK检索数据失败,错误为500

使用Uber Rides Python SDK检索数据失败,错误为500,python,uber-api,Python,Uber Api,在学习了本教程之后,我在尝试获取诸如用户配置文件或活动之类的数据时遇到了错误 这是我的样本(烧瓶)代码: 这可能是优步服务的问题吗 更新: 根据请求调试跟踪 Starting WSGIServer type flask on 127.0.0.1:8080 ... INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit) INFO:werkzeug:127.0.0.1 - - [15/Jan/2017 18:

在学习了本教程之后,我在尝试获取诸如用户配置文件或活动之类的数据时遇到了错误

这是我的样本(烧瓶)代码:

这可能是优步服务的问题吗

更新: 根据请求调试跟踪

Starting WSGIServer type flask on 127.0.0.1:8080 ...
INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
INFO:werkzeug:127.0.0.1 - - [15/Jan/2017 18:58:09] "GET / HTTP/1.1" 302 -
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): login.uber.com
DEBUG:requests.packages.urllib3.connectionpool:https://login.uber.com:443 "POST /oauth/token HTTP/1.1" 200 None
INFO:werkzeug:127.0.0.1 - - [15/Jan/2017 18:58:19] "GET /callback?state=z9ga01Y6kgNFRbgDbeEA3IjCYLMTnI7M&code=wwTzfIbFivsCoGE4RIu0rDb2fO22NI HTTP/1.1" 200 -
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): sandbox-api.uber.com
DEBUG:requests.packages.urllib3.connectionpool:https://sandbox-api.uber.com:443 "GET /v1.2/me HTTP/1.1" 500 75
INFO:werkzeug:127.0.0.1 - - [15/Jan/2017 18:58:35] "GET /profile HTTP/1.1" 500 -
ERROR:werkzeug:Error on request:
更新2:请求模块日志记录

Starting WSGIServer type flask on 127.0.0.1:8080 ...
INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
^C(venv) Davids-MacBook-Pro:uber crazywizard$ clear
(venv) Davids-MacBook-Pro:uber crazywizard$ python app.py
Starting WSGIServer type flask on 127.0.0.1:8080 ...
INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
INFO:werkzeug:127.0.0.1 - - [17/Jan/2017 22:35:04] "GET / HTTP/1.1" 302 -
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): login.uber.com
send: 'POST /oauth/token HTTP/1.1\r\nHost: login.uber.com\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.12.4\r\nContent-Length: 217\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\ncode=Mg1VBWKR0V0ioeLYTAv61pAbjy3WD4&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fcallback&client_id=xxx&client_secret=xxx&grant_type=authorization_code'
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx
header: Date: Tue, 17 Jan 2017 19:35:08 GMT
header: Content-Type: application/json
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Pragma: no-cache
header: Cache-Control: no-store
header: Set-Cookie: session=ab5c70960ceb1415_587e71ec.pJiJyH80bf4wULzs_NpDCMc-Ymw; Domain=login.uber.com; Secure; HttpOnly; Path=/
header: X-Uber-App: login
header: Strict-Transport-Security: max-age=604800
header: X-Content-Type-Options: nosniff
header: X-XSS-Protection: 1; mode=block
header: Strict-Transport-Security: max-age=2592000
header: X-Frame-Options: SAMEORIGIN
header: Cache-Control: max-age=0
header: Content-Encoding: gzip
DEBUG:requests.packages.urllib3.connectionpool:https://login.uber.com:443 "POST /oauth/token HTTP/1.1" 200 None
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): sandbox-api.uber.com
send: 'GET /v1/products?latitude=37.77&longitude=-122.41 HTTP/1.1\r\nHost: sandbox-api.uber.com\r\nAccept-Encoding: identity\r\nX-Uber-User-Agent: Python Rides SDK v0.2.7\r\nAuthorization: Bearer xxx\r\n\r\n'
reply: 'HTTP/1.1 500 Internal Server Error\r\n'
header: Server: nginx
header: Date: Tue, 17 Jan 2017 19:35:09 GMT
header: Content-Type: application/json
header: Content-Length: 75
header: Connection: keep-alive
header: X-Uber-App: uberex-sandbox
header: X-Uber-App: migrator-uberex-sandbox-optimus
header: Strict-Transport-Security: max-age=604800
header: X-Content-Type-Options: nosniff
header: X-XSS-Protection: 1; mode=block
DEBUG:requests.packages.urllib3.connectionpool:https://sandbox-api.uber.com:443 "GET /v1/products?latitude=37.77&longitude=-122.41 HTTP/1.1" 500 75
INFO:werkzeug:127.0.0.1 - - [17/Jan/2017 22:35:10] "GET /callback?state=dH1nnut35q9xcOdC3W9a1lFKNqGXn9h5&code=Mg1VBWKR0V0ioeLYTAv61pAbjy3WD4 HTTP/1.1" 500 -
ERROR:werkzeug:Error on request:
更新3: 我深入研究了rides_python_sdk,并添加了额外的标题,如文档所示

我还将
Accept Encoding
参数更正为sdk中的内容
['gzip,deflate']

仍然得到500的错误

DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.uber.com
send: 'GET /v1.2/products?latitude=37.77&longitude=-122.41 HTTP/1.1\r\nHost: api.uber.com\r\nAccept-Language: en_EN\r\nX-Uber-User-Agent: Python Rides SDK v0.3.1\r\nContent-Type: application/json\r\nAccept-Encoding: gzip, deflate\r\nAuthorization: Bearer ppdHHakR8EQL09kpAIrPYkDCAWFHQT\r\n\r\n'
reply: 'HTTP/1.1 500 Internal Server Error\r\n'
header: Server: nginx
header: Date: Wed, 18 Jan 2017 09:46:04 GMT
header: Content-Type: application/json
header: Content-Length: 75
header: Connection: keep-alive
header: X-Uber-App: uberex-nonsandbox
header: X-Uber-App: migrator-uberex-optimus
header: Strict-Transport-Security: max-age=604800
header: X-Content-Type-Options: nosniff
header: X-XSS-Protection: 1; mode=block

谢谢你在我调查这个问题时的耐心。这是v1oauth端点中的一个潜在错误,影响了新创建的应用程序。我已经发布了解决这个问题的sdk的新版本。请使用v0.4.0,您不应该有任何问题。感谢您的详细反馈

我不得不使用另一个oauth库(flask_oauthlib)

导入操作系统、请求、日志
将httplib作为http_客户端导入
从日期时间导入日期时间
从烧瓶导入烧瓶,请求,闪存,url\u,重定向
从flask_oauthlib.client导入OAuth
从flask导入会话,重定向
app=烧瓶(名称)
app.config.from_pyfile('flaskapp.cfg'))
http_client.HTTPConnection.debuglevel=1
logging.basicConfig(级别=logging.DEBUG)
requests\u log=logging.getLogger(“requests.packages.urllib3”)
请求\u log.setLevel(logging.DEBUG)
请求\u log.propagate=True
oauth=oauth()
uber\u app=oauth.remote\u app(
“优步”,
请求\u令牌\u url=None,
访问\u令牌\u url=https://login.uber.com/oauth/v2/token',
授权https://login.uber.com/oauth/v2/authorize',
消费者密钥=“”,
消费者机密=“”
)
@应用程序路径(“/”)
def index():
#致电优步服务获取产品
headers={'Authorization':'Bearer'+会话['uber_token'][0]}
url=”https://api.uber.com/v1.2/"
response_profile=requests.get(url+'me',headers=headers)
response_history=requests.get(url+'history',headers=headers)
返回“Profile”+response\u Profile.content+“History”+response\u History.content,200
@uber_app.tokengetter
def get_uber_令牌(令牌=无):
return session.get('uber\u token')
@app.route(“/login”)
def login():
返回uber\u app.authorize(callback=url\u for('oauth\u authorized'),\u external=True,
next=request.args.get('next')或request.referer或None)
@应用程序路径(“/oauth authorized”)
def oauth_authorized():
next\u url=request.args.get('next')或url\u for('index')
resp=uber\u app.authorized\u response()
如果resp为无:
flash(您拒绝了登录请求。)
返回重定向(下一个url)
会话['uber_令牌']=(
resp['access_token'],
resp['refresh_token']
)
flash('您已登录')
返回重定向(下一个url)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app.run(debug=True)
  • 首先创建一个oauth实例,并将参数分配到
    remote\u app
    方法中 注意:oauth2.0没有
    request\u token\u url
    ,因此将其设置为
    None

  • get\u uber\u token
    方法创建一个全局会话来存储您的令牌,您可以从代码中的任何其他位置访问该令牌

  • /login
    将用户重定向到Uber登录页面。作为url的一部分,Uber将使用重定向uri回调您的服务

  • 注意:确保在
    url\u for
    方法中添加
    \u external=True
    参数,以便生成uber服务回调所需的绝对url

  • “oauth_authorized”方法和端点在授权阶段后处理来自Uber服务的重定向。记住获取并存储您稍后需要的两个重要代币<代码>访问\u令牌和
    刷新\u令牌

  • index
    方法中,在授权成功后,它最终重定向到该方法,我已经调用了一些调用来获取概要文件和骑手历史记录以进行演示。注意发送的标题


  • 注意:请注意,承载令牌大约在10分钟后过期,您需要刷新令牌才能请求另一个承载令牌。这里的日志只是将所有内容设置为
    DEBUG
    级别,以便您可以查看发送的内容。

    我可能是他们的服务出错。。。更有可能是他们的服务未正确处理的错误请求或其他原因……看起来Uber api有错误。您仍然看到此问题吗?@DustinWhittle是的,很遗憾,仍然收到相同的错误。您可以共享确切的请求和响应吗?@DustinWhittle检查更新承载令牌不应该这么快过期,但您可以始终使用刷新令牌来获取新的访问令牌。
    Starting WSGIServer type flask on 127.0.0.1:8080 ...
    INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
    ^C(venv) Davids-MacBook-Pro:uber crazywizard$ clear
    (venv) Davids-MacBook-Pro:uber crazywizard$ python app.py
    Starting WSGIServer type flask on 127.0.0.1:8080 ...
    INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
    INFO:werkzeug:127.0.0.1 - - [17/Jan/2017 22:35:04] "GET / HTTP/1.1" 302 -
    DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): login.uber.com
    send: 'POST /oauth/token HTTP/1.1\r\nHost: login.uber.com\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.12.4\r\nContent-Length: 217\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\ncode=Mg1VBWKR0V0ioeLYTAv61pAbjy3WD4&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fcallback&client_id=xxx&client_secret=xxx&grant_type=authorization_code'
    reply: 'HTTP/1.1 200 OK\r\n'
    header: Server: nginx
    header: Date: Tue, 17 Jan 2017 19:35:08 GMT
    header: Content-Type: application/json
    header: Transfer-Encoding: chunked
    header: Connection: keep-alive
    header: Pragma: no-cache
    header: Cache-Control: no-store
    header: Set-Cookie: session=ab5c70960ceb1415_587e71ec.pJiJyH80bf4wULzs_NpDCMc-Ymw; Domain=login.uber.com; Secure; HttpOnly; Path=/
    header: X-Uber-App: login
    header: Strict-Transport-Security: max-age=604800
    header: X-Content-Type-Options: nosniff
    header: X-XSS-Protection: 1; mode=block
    header: Strict-Transport-Security: max-age=2592000
    header: X-Frame-Options: SAMEORIGIN
    header: Cache-Control: max-age=0
    header: Content-Encoding: gzip
    DEBUG:requests.packages.urllib3.connectionpool:https://login.uber.com:443 "POST /oauth/token HTTP/1.1" 200 None
    DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): sandbox-api.uber.com
    send: 'GET /v1/products?latitude=37.77&longitude=-122.41 HTTP/1.1\r\nHost: sandbox-api.uber.com\r\nAccept-Encoding: identity\r\nX-Uber-User-Agent: Python Rides SDK v0.2.7\r\nAuthorization: Bearer xxx\r\n\r\n'
    reply: 'HTTP/1.1 500 Internal Server Error\r\n'
    header: Server: nginx
    header: Date: Tue, 17 Jan 2017 19:35:09 GMT
    header: Content-Type: application/json
    header: Content-Length: 75
    header: Connection: keep-alive
    header: X-Uber-App: uberex-sandbox
    header: X-Uber-App: migrator-uberex-sandbox-optimus
    header: Strict-Transport-Security: max-age=604800
    header: X-Content-Type-Options: nosniff
    header: X-XSS-Protection: 1; mode=block
    DEBUG:requests.packages.urllib3.connectionpool:https://sandbox-api.uber.com:443 "GET /v1/products?latitude=37.77&longitude=-122.41 HTTP/1.1" 500 75
    INFO:werkzeug:127.0.0.1 - - [17/Jan/2017 22:35:10] "GET /callback?state=dH1nnut35q9xcOdC3W9a1lFKNqGXn9h5&code=Mg1VBWKR0V0ioeLYTAv61pAbjy3WD4 HTTP/1.1" 500 -
    ERROR:werkzeug:Error on request:
    
    DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.uber.com
    send: 'GET /v1.2/products?latitude=37.77&longitude=-122.41 HTTP/1.1\r\nHost: api.uber.com\r\nAccept-Language: en_EN\r\nX-Uber-User-Agent: Python Rides SDK v0.3.1\r\nContent-Type: application/json\r\nAccept-Encoding: gzip, deflate\r\nAuthorization: Bearer ppdHHakR8EQL09kpAIrPYkDCAWFHQT\r\n\r\n'
    reply: 'HTTP/1.1 500 Internal Server Error\r\n'
    header: Server: nginx
    header: Date: Wed, 18 Jan 2017 09:46:04 GMT
    header: Content-Type: application/json
    header: Content-Length: 75
    header: Connection: keep-alive
    header: X-Uber-App: uberex-nonsandbox
    header: X-Uber-App: migrator-uberex-optimus
    header: Strict-Transport-Security: max-age=604800
    header: X-Content-Type-Options: nosniff
    header: X-XSS-Protection: 1; mode=block
    
    import os, requests, logging
    import httplib as http_client
    from datetime import datetime
    from flask import Flask, request, flash, url_for, redirect
    
    from flask_oauthlib.client import OAuth
    from flask import session, redirect
    
    app = Flask(__name__)
    app.config.from_pyfile('flaskapp.cfg')
    
    http_client.HTTPConnection.debuglevel = 1
    logging.basicConfig(level=logging.DEBUG)
    requests_log = logging.getLogger("requests.packages.urllib3")
    requests_log.setLevel(logging.DEBUG)
    requests_log.propagate = True
    
    oauth = OAuth()
    uber_app = oauth.remote_app(
            'uber',
            request_token_url=None,
            access_token_url='https://login.uber.com/oauth/v2/token',
            authorize_url='https://login.uber.com/oauth/v2/authorize',
            consumer_key='<client_id>',
            consumer_secret='<client_secret>'
        )
    
    @app.route('/')
    def index():
        #Make call to Uber service to retrieve products
        headers = {'Authorization' : 'Bearer '+session['uber_token'][0]}
        url = "https://api.uber.com/v1.2/"
        response_profile = requests.get(url+'me', headers=headers)
        response_history = requests.get(url+'history', headers=headers)
    
        return "<h3>Profile</h3><p>"+response_profile.content+"<h3>History</h3>"+response_history.content, 200
    
    @uber_app.tokengetter
    def get_uber_token(token=None):
        return session.get('uber_token')
    
    @app.route('/login')
    def login():
        return uber_app.authorize(callback=url_for('oauth_authorized', _external=True,
            next=request.args.get('next') or request.referrer or None))
    
    @app.route('/oauth-authorized')
    def oauth_authorized():
        next_url = request.args.get('next') or url_for('index')
        resp = uber_app.authorized_response()
        if resp is None:
            flash(u'You denied the request to sign in.')
            return redirect(next_url)
    
        session['uber_token'] = (
            resp['access_token'],
            resp['refresh_token']
        )
    
        flash('You were signed in')
        return redirect(next_url)
    
    if __name__ == '__main__':
        app.run(debug=True)