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"
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"
Try this:
import urllib
website = urllib.urlopen('http://www.google.com/')
siteData = website.read()
print siteData
It might help.
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>"