4

I am using the request library to do a GET request. I can get a 200 response but it returns no data, it returns the object 'jobs' but then nothing else. I am using the Visualping.io api. I have successfully run CURl commands, and Success from browser url.... Here is my python code. I have edited out my credentials and PHP sesh id.

`import requests
r = requests.get("https://visualping.io/api/job/list", headers={'username':'[email protected]', 'password':'MyPassword', 'User-Agent':'test'})
print (r.content)
print (r.status_code)
print (r.headers)
print (r.json)`

I have also tried without the user and pass as headers, and just passed them in the url like this.. Again this works from a browser and curl

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

For both of these, I get the following output

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

//Print status code 200

//Below is print headers

{'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'}

//This is print json {u'jobs': [], u'success': True}

Here it is in one block

`{"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

Here is an expected response from the documentation 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"
          }  
        ],
    }
}`
1
  • Update: passing no credentials yields the same result"success":true,"jobs":[]} 200 {'X-Powered-By': 'PHP/5.5.35', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'PHPSESSID=9aq0m56d1otm617hoidnl40np4; expires=Fri, 26-May-2017 21:12:55 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 20:12:55 GMT', 'Content-Type': 'text/html', 'Content-Encoding': 'gzip'} Commented May 26, 2017 at 20:13

2 Answers 2

6

json is a function, please try this one:

print(r.json())

So, you're just missing parentheses. You're accessing a method as you can see in your output:

<bound method Response.json of <Response [200]>>
Sign up to request clarification or add additional context in comments.

Comments

4

The docs you linked to for VisualPings api say they only support HTTP Basic Auth so try:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.