Search code examples
pythoncurlurllib2pycurl

Python code like curl


in curl i do this:

curl -u email:password http://api.foursquare.com/v1/venue.json?vid=2393749

How i can do this same thing in python?


Solution

  • "The problem could be that the Python libraries, per HTTP-Standard, first send an unauthenticated request, and then only if it's answered with a 401 retry, are the correct credentials sent. If the Foursquare servers don't do "totally standard authentication" then the libraries won't work.

    Try using headers to do authentication:"

    taked from Python urllib2 Basic Auth Problem

    import urllib2
    import base64
    
    req = urllib2.Request('http://api.foursquare.com/v1/venue.json?vid=%s' % self.venue_id)
    req.add_header('Authorization: Basic ',base64.b64encode('email:password'))
    res = urllib2.urlopen(req)