【发布时间】:2019-12-18 17:22:57
【问题描述】:
我是 Python 编程的新手,我正在尝试使用电动滑板车租赁服务并从滑板车上抓取数据。服务提供商是 Bird,没有官方 API,只能通过 Android 或 iOS 应用程序访问。有人找到了一种方法,这里记录了帖子和获取的要求:https://github.com/ubahnverleih/WoBike/blob/master/Bird.md
我的问题是在我通过令牌授权自己之后,我无法创建获取请求。服务器一直在说: {"code":401,"message":"访问此资源需要凭据"}
这是我的代码:
import requests
import json
import uuid
target = "https://api-auth.prod.birdapp.com/api/v1/auth/email"
headers = { "User-Agent": "Bird/4.53.0 (co.bird.Ride; build:24; iOS 12.4.1) Alamofire/4.53.0"
,"Platform": "ios",
"App-Version": "4.53.0",
"Content-Type": "application/json",
"Device-Id": str(uuid.uuid4())}
data = {"email": "any@mail.com"}
reply = requests.post(target, data=json.dumps(data), headers=headers)
# at this point u get an email and u need to copy the token in the email
token = {"token":"IGzMtdAkQ3icmSFV0V64yQ"}
url_token = 'https://api-auth.prod.birdapp.com/api/v1/auth/magic-link/use'
# now you are authorized and you can start get-requests
get_headers = {"Authorization" : "IGzMtdAkQ3icmSFV0V64yQ",
"Device-id" : str(uuid.uuid4()),
"App-Version" : "4.41.0",
"Location" : json.dumps({"latitude":37.77249,"longitude":-122.40910,"altitude":500,"accuracy":100,"speed":-1,"heading":-1})}
url_get_birds = "https://api.birdapp.com/bird/nearby?latitude=37.77184&longitude=-122.40910&radius=1000"
print((requests.get(url_get_birds, headers = get_headers)).text)
最后一个打印命令总是给我 401 错误
我想我不使用 get_headers 中的令牌作为正确的授权...... 很抱歉打扰你,但我真的不知道如何进步。
非常感谢
【问题讨论】:
标签: python web-crawler authorization http-status-code-401