0

All, I'm getting some strange behavior trying to use requests for an https call into the gitub api:

print(requests.get('https://api.github.com/gists/bbc56a82f359eccd4bd6').text)

The output looks like printing a binary file (no point in pasting the garbled output here).

An equivalent cURL call ("curl https://api.github.com/gists/bbc56a82f359eccd4bd6") results in the JSON response I'm expecting.

All this started after fixing a pip issue (InsecurePlatformWarning), where a few security-related packages were installed. This fix is required for users of python<2.7.9. I'm on 2.7.3 as it was recommended on some sites not to touch the python build on debian (for dependency-breaking issues).

Note that the issue that i'm having breaks functionality for e.g. github3py python API wrapper, etc.

Is anyone else seeing issues with requests after the upgrade? Any fixes?

Community
  • 1
  • 1
GG_Python
  • 3,436
  • 5
  • 34
  • 46

2 Answers2

0

This URL clearly responds differently depending on user-agent. I could make the curl command line response differ by simply adding -A moo/1.

You can probably get a curl-like response with Requests from this by using a curl like user-agent.

Or even better: just ask github or read up on their API.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
0

I'm not seeing that behaviour here:

>>> import requests
>>> print(requests.get('https://api.github.com/gists/bbc56a82f359eccd4bd6').text)

Returns a JSON string. You could try debugging this further by changing the User-Agent of your request call to be that of cURL:

headers = {
    'User-Agent': 'curl/7.38.0',
}
url = 'https://api.github.com/gists/bbc56a82f359eccd4bd6'
response = requests.get(url, headers=headers)
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159