-2
當我使用curl運行以下API查詢我得到JSON響應與訪問令牌不工作
curl -X GET --header 'Accept: application/json' --header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c' 'https://localhost:10010/v1/machines'
但是,當我試圖使用python請求我收到拒絕訪問的錯誤運行相同的查詢Python的請求必須與結果碼403 下面供應授權令牌是我試圖
import requests
url = 'https://localhost:10010/v1/machines'
head = {'Authorization': 'access_token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c'}
response = requests.get(url, headers=head)
print response.text
請讓我知道,如果我在這裏做了錯事的Python代碼。 謝謝。
您已經命名的令牌不同的東西,併發送不同通常在每種情況下都是標題。 – pvg
@pvg請詳細說明。我無法理解。請讓我知道如何糾正。 – cgoma
@ChetanGomase試試這個:'{'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c'}' –