第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自動生成訪問令牌

自動生成訪問令牌

翻閱古今 2022-07-05 19:11:12
為了從私有 API 中提取數(shù)據(jù),我需要使用我的身份驗證密鑰和憑據(jù)生成訪問令牌。我當前的代碼分為兩部分。第一個生成訪問令牌:import requests url = "https://api.abcdef.com/AuthorizationServer/Token" payload = "{\r\n    \"grant_type\" : \"password\",\r\n    \"username\" : \"user@aldfh.com\",\r\n  \"password\" : \"kajshdgfkuyb\",\r\n    \"scope\" : \"API\"\r\n}" headers = {   'Content-Type': 'application/json',   'Authorization': 'Basic VGFibGVhdV9DaW94QFRhYmxlYXVfQ2lveDo0Ix ' } response = requests.request("POST", url, headers=headers, data = payload) print(response.text.encode('utf8'))響應如下所示:    {"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpY0JVSWQiOjQ1OTg0MjEsIm5hbWUiOiJyYW15YS5nb3RldHlAY2lveGhlYWx0aC5jb20iLCJpc3MiOiJodHRwczovL2FwaS5pbmNvbnRhY3QuY29tIiwic3ViIjoidXNlcjoxNTMyMDI2MiIsImF1ZCI6IlRhYmxlYXVfQ2lveEBUYWJsZWF1X0Npb3giLCJleHAiOjE1Nzk2Mjg1NzcsImlhdCI6MTU3OTYyNDk3OCwiaWNTY29wZSI6IjgiLCJpY0NsdXN0ZXJJZCI6IkMzMSIsImljQWdlbnRJZCI6MTUzMjAyNjIsImljU1BJZCI6MTQ5NiwibmJmIjoxNTc5NjI0OTc4fQ.rEZiMHPsE1inwuWFME1oV_oD54TqkU00-uml3NjCkClW3R-_bVC7A3PxI4zGlJms1rvsZkgO3XX8-1coeV6_jtI-l3nCHixVk2nboepqAspoxT3o9w4vhBhZzvs-TAsqyk4fCrSwwHFXwn8xOMdfrqZqknXHLlVtKlGJg_Uy3bmwEiioocMN3BRZE_269_v5Ez4b94_juUHLPDWye7kS5-8cs4Izsk7HePn-Sm_-FLEqEeb2C09NUGWU8SdyA3EtQhMAiHkU-wN8uQ8wKcWoUfO7WtrSO4zbicFZHgA9Cw","token_type":"bearer","expires_in":3600,"refresh_token":"pDYllH2UsVIYq3Pn3Dg==","scope":"Api","resource_server_base_uri":"https://api-c31.it.com/itAPI/","refresh_token_server_uri":"https://api-c31.it.com/AuthorizationServer/Token","agent_id":162,"team_id":24355,"bus_no":4421}'訪問令牌是輸出的一部分,我將其粘貼到以下代碼中以生成響應:def getPerformance():# api-endpoint #Give the specified url ,accessToken    BASEURL = 'https://api-c31.ict.com/tAPI/'我的問題是我需要能夠合并兩個腳本才能使該過程自動化。
查看完整描述

2 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

嘗試將以下更改添加到代碼的第一部分,然后使用底部的訪問令牌將其傳遞給getPerformance()函數(shù):


#Added json import here


import json

import requests



url = "https://api.abcdef.com/AuthorizationServer/Token"


payload = "{\r\n    \"grant_type\" : \"password\",\r\n    \"username\" : \"user@aldfh.com\",\r\n  \"password\" : \"kajshdgfkuyb\",\r\n    \"scope\" : \"API\"\r\n}"


headers = {

     'Content-Type': 'application/json',

     'Authorization': 'Basic VGFibGVhdV9DaW94QFRhYmxlYXVfQ2lveDo0Ix '

     }


response = requests.request("POST", url, headers=headers, data = payload)


#Note the changes here


json = response.read()

data = json.loads(json)



accessToken = data['access_token']

然后,無論您在哪里調用getPerformanceFunction(),都希望將其更改為getPerformance(accessToken)。您也需要將函數(shù)定義更改為此。


查看完整回答
反對 回復 2022-07-05
?
慕容森

TA貢獻1853條經驗 獲得超18個贊

根據(jù)上面@Cutter 的回復,進行以下更改對我有用:


import requests

import json


 url = "https://api.abcdef.com/AuthorizationServer/Token"


 payload = "{\r\n    \"grant_type\" : \"password\",\r\n    \"username\" : \"user@aldfh.com\",\r\n  \"password\" : \"kajshdgfkuyb\",\r\n    \"scope\" : \"API\"\r\n}"


 headers = {

   'Content-Type': 'application/json',

   'Authorization': 'Basic VGFibGVhdV9DaW94QFRhYmxlYXVfQ2lveDo0Ix '

 }


 response = requests.request("POST", url, headers=headers, data = payload)

 testresp = response.text

 data = json.loads(testresp)

#將函數(shù)定義更改為:


def getPerformance(data):


# api-endpoint 

#Give the specified url ,accessToken

# =============================================================================

    BASEURL = 'https://api-c31.ict.com/API/'

    accessToken = (data["access_token"])


查看完整回答
反對 回復 2022-07-05
  • 2 回答
  • 0 關注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號