0

I want to convert following command in python.

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET "https://api.globalgiving.org/api/public/projectservice/all/projects/ids?api_key=YOUR_API_KEY"
fredtantini
  • 15,966
  • 8
  • 49
  • 55
Trupti
  • 1
  • 2

2 Answers2

0

Try this:

import urllib

website = urllib.urlopen('http://www.google.com/') 
siteData = website.read()
print siteData

It might help.

Gaurav Dave
  • 6,838
  • 9
  • 25
  • 39
0

I am not the only one, who would recommend using great HTTP for Humans library called requests.

Install it:

$ pip install requests

And use as follows:

>>> import requests
>>> headers = {"Accept": "application/xml", "Content-Type": "application/xml"}
>>> url = "https://api.globalgiving.org/api/public/projectservice/all/projects/ids"
>>> req = requests.get(url, headers=headers, params={"api_key": "YOUR_API_KEY"})
>>> req.ok
False
>>> req.status_code
401
>>> req.text
u"<?xml version='1.0' encoding='UTF-8'?>\n<error_response>\n  <error_code>401</error_code>\n  <errors>\n    <error>\n      <error_message>api_key [YOUR_API_KEY] is not registered in the system.</error_message>\n    </error>\n  </errors>\n  <status>Unauthorized</status>\n</error_response>"
Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98