我正在使用请求库执行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)`
我也尝试过不使用用户和pass作为头,只是在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,2017年5月26日20:42:31 GMT;Max-Age=3600;path=/','expires':'Thu,1981年11月19日08:52:00 GMT','Vary':'Accept-Encoding','Server':'nginx',Connection':'keep alive','Pragma':'no-cache','cache-Control:'没有存储,没有缓存,必须重新验证日期,post check=0,pre check=0,'日期':'Fri,2017年5月26日19:42:31 GMT,'内容类型':'text/html,'内容编码':'gzip'}
//这是print 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
以下是文档中的预期响应 获取/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"
}
],
}
}`
您为VisualPings api链接的文档表示它们只支持HTTP基本身份验证,因此请尝试:
Requests Basic Auth docs
json
是一个函数,请尝试此函数:所以,你只是缺少括号。您正在访问一个方法,如您在输出中所见:
相关问题 更多 >
编程相关推荐