我正在使用request库进行GET请求。我可以获得200响应,但它没有返回任何数据,仅返回对象“jobs”,但之后没有其他内容。我正在使用Visualping.io api。我已经成功运行了CURl命令,并从浏览器URL中获得成功。这是我的Python代码。我已编辑掉了我的凭据和PHP sesh id。
`import requests
r = requests.get("https://visualping.io/api/job/list", headers={'username':'myemail@email.com', 'password':'MyPassword', 'User-Agent':'test'})
print (r.content)
print (r.status_code)
print (r.headers)
print (r.json)`
我还尝试过不将用户和密码作为标头传递,而是像这样将它们直接传递到URL中。同样,在浏览器和curl中都能正常工作。
`https://visualping.io/api/job/list?username='myusername'&password='mypassword'`
对于这两个,我得到以下输出
//printcontent {"success":true,"jobs":[]}
//打印状态码 200
//下面是打印标头
{'X-Powered-By': 'PHP/5.5.35', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'PHPSESSID={MYSESSIONID}; expires=Fri, 26-May-2017 20:42:31 GMT; Max-Age=3600; path=/', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Vary': 'Accept-Encoding', 'Server': 'nginx', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Date': 'Fri, 26 May 2017 19:42:31 GMT', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip'}
//这是打印json {u'jobs': [], u'success': True}
这是整块内容
`{"success":true,"jobs":[]}
200
{'X-Powered-By': 'PHP/5.5.35', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'PHPSESSID={MYSESSIONID}; expires=Fri, 26-May-2017 20:43:47 GMT; Max-Age=3600; path=/', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Vary': 'Accept-Encoding', 'Server': 'nginx', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Date': 'Fri, 26 May 2017 19:43:47 GMT', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip'}
<bound method Response.json of <Response [200]>>`
https://company-32327.frontify.com/d/Lr7wNKb1omxI/visualping-api
以下是文档中预期响应:
GET /api/job/list
`{
"jobs": {
"active": [
{
"id": "NzqkVe1AI6WYBli",
"created": "2015-09-06 00:37:16",
"url": "www.google.de",
"description": "Google Landing Page",
"runs": "10",
"trigger": "1",
"interval": "60",
}
],
"inactive": [
{
"id": "gCXHiydaCulFOFA",
"created": "2016-09-06 00:37:16",
"url": "www.bing.de",
"description": "Bing Landing Page",
"runs": "25",
"trigger": "10",
"interval": "300"
}
],
}
}`