0
我試着做出的API請求:使用https://www.trakomatic.com/Http請求
代碼:
import requests
url = 'https://webapi.trakomatic.com/....'
head1 = {'Authorization': 'access_token 066bf0a8d74xxxx'}
head2 = {'Authorization': '066bf0a8d74xxxx'}
head3 = {'Authorization': 'Token : 066bf0a8d74xxxx'}
head4 = {"Token":"066bf0a8d74xxxx"}
response = requests.post(url, headers= head3)
的API需要一個令牌,使一個HTTP request.Currently我使用提供的令牌通過API,可能即將過期。我收到以下錯誤。
>>>response.text
u'{"Status":"ERROR","Message":"Invalid or NULL token","Data":null}'
>>>response
<Response [200]>
我已經試過了頭的各種格式,因爲我懷疑這也許是原因,但都無濟於事。 有沒有一種方法可以使用用戶名和密碼來生成令牌?我在做什麼有什麼問題?
API的認證頁面有這樣的:
URL Format[web api server]/account/authenticate/
URLhttps://webapi.trakomatic.com/account/authenticate/
Parameter(s){ LoginName: , Password: }
嘗試使用要求:
from requests.auth import HTTPBasicAuth
u = 'xxx'
p = 'xxx'
>>>
a=requests.post('https://webapi.trakomatic.com/account/authenticate/', auth=HTTPBasicAuth('u', 'p'))
>>> a
<Response [200]>
>>> a.json()
{u'Status': u'ERROR', u'LoginName': None, u'CorporationId': 0, u'Token': None, u'Msg': u'Invalid information to login', u'Password': None}
使用請求會話 - 記錄在使用會話時應該提供cookie,這些cookie將被存儲在會話中,並通過請求自動提供每個後續請求使用會話。即,除非是服務記錄需要在報頭中提供的實際API密鑰,否則不應該手動提供令牌 – barny
至少理解正在發生的事情的另一種方式是使用例如網絡瀏覽器來窺探瀏覽器登錄。提琴手 – barny
更新的問題,是你所指的。 – user3243478