2

When I do curl, I get a response:

root@3d7044bac92f:/home/app/tmp# curl -H "Content-type: application/json" -X GET https://github.com/timeline.json -k 

{"message":"Hello there, wayfaring stranger. If you\u2019re reading this then you probably didn\u2019t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.","documentation_url":"https://developer.github.com/v3/activity/events/#list-public-events"}

However, when I do python requests to the same URL I get a status 410.

import requests

headers = {
    'Content-type': 'application/json',
}

r = requests.get('https://github.com/timeline.json')
print r.json

root@3d7044bac92f:/home/app/tmp# python rest.py 
<bound method Response.json of <Response [410]>>

What gives?

The host is a standard Ubuntu docker image and only installed Curl and some python modules. Python -V is 2.7

Note: I looked at this question but I can't telnet into above server so that solution doesn't apply to me: Curl works but not Python requests

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
NTDF
  • 31
  • 1
  • 4

1 Answers1

3

You've made at least two errors in your program.

1) You haven't specified the data= or headers parameters to the requests.get() call. Try this:

 r = requests.get('https://github.com/timeline.json', data=data, headers=headers)

2) .json is a method, not a data attribute of the response object. As a method, it must be called in order to be effective. Try this:

print r.json()
Robᵩ
  • 163,533
  • 20
  • 239
  • 308