谁能告诉我如何使用Python 3进行自动化并向api发送GET请求
第一步-授权 2个步骤-获取地图(在Google Chrome中使用F12:)
General:
Request URL: https://xxxxxxxxxxru/api/v2/offices/270/couriers?limit=100&offset=0
Request Method: GET
Status Code: 200
Remote Address: xxx.yyy.zzz.aaa:abc
Referrer Policy: no-referrer-when-downgrade
Response headers:
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-type: application/json;charset=UTF-8
date: Wed, 14 Aug 2019 09:15:51 GMT
expires: 0
pragma: no-cache
server: nginx
status: 200
vary: Accept-Encoding
x-content-type-options: nosniff
x-frame-options: DENY
x-powered-by: Express
x-xss-protection: 1; mode=block
Provisional headers are shown
Request headers:
Accept: application/json, text/plain, */*
PWT: xxxxxxxxyyyyyyyyyzzzzzz
etc
我的代码:
from requests.auth import HTTPDigestAuth
#import autorization
import requests
url_1="https://xxxxxxxxxxxxx.ru/api/v2/maps?dateEnd=2019-08-14&dateStart=2019-08-14&limit=100&officeCode=270&offset=0&onlyEmpty=false&typeBasis="
headers1 = {
'Accept': 'application/json,',
'Accept': 'text/plain',
'Accept': '*/*',
'PWT': 'xxxxxxyyyyyyyyyyyzzzzzzz',
'Referer': 'https://xxxxxxxxxxxxx.ru/',
'Sec-Fetch-Mode': 'cors',
'X-Auth-Token': 'xxxxxxyyyyyyyyyyyzzzzzzz',
'X-User-Lang': 'rus'}
response = requests.get(url_1, headers=headers1)
print(response)
答案 0 :(得分:0)
很容易,哈哈。只有应该做的-在“ print(response)”的末尾添加“ .text”,即“ print(response.text)” 运行请求后,我得到了正确的响应