Python请求Get(URL)200响应,没有数据

时间:2017-05-26 20:03:02

标签: python python-2.7 api

我正在使用请求库来执行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中传递它们。再次,这可以从浏览器和卷曲

`https://visualping.io/api/job/list?username='myusername'&password='mypassword'`

对于这两个,我得到以下输出

// printcontent {" success":true," jobs":[]}

//打印状态代码200

//下面是打印标题

{' X-Powered-By':' PHP / 5.5.35','转码编码':' chunked', ' Set-Cookie':' PHPSESSID = {MYSESSIONID};到期= 2017年5月26日星期五20:42:31 GMT;最大年龄= 3600; path = /',' Expires':' Thu,1981年11月19日08:52:00 GMT',' Vary':'接受-Encoding',' Server':' nginx',' Connection':' keep-alive',' Pragma&# 39;:' no-cache',' Cache-Control' no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0','日期':'星期五,26五月2017 19:42:31 GMT','内容类型':'文字/ html','内容编码':' gzip'}

//这是打印json {u'工作':[],u'成功':真实}

这是一个块

`{"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"
          }  
        ],
    }
}`

2 个答案:

答案 0 :(得分:2)

radtest test aaaaaaaaaaaaaaaaaaa <ipaddress and port 1 mysecert Sending Access-Request of id 167 to <Ipaddress and port> User-Name = "test" User-Password = "aaaaaaaaaaaaaaaaaaa" NAS-IP-Address = 255.255.255.255 NAS-Port = 1 是一个函数,请尝试这个:

json

所以,你只是缺少括号。您可以在输出中看到正在访问的方法:

print(r.json())

答案 1 :(得分:1)

你为VisualPings api链接的文档说他们只支持HTTP Basic Auth所以试试:

import requests
from requests.auth import HTTPBasicAuth
r = requests.get("https://visualping.io/api/job/list", auth=HTTPBasicAuth('myusername', 'mypassword'))
print(r.json())

Requests Basic Auth docs