AttributeError: 'tuple' object has no attribute 'startswith' when using Python httplib

I'm trying fetch account information by python, which's OAuth 1.0. And I have the code below:

token_url = "oauth/token?" + urlencode(ksort(params)) + "&sig=%s",sig
conn = httplib.HTTPSConnection(url, 443)
conn.request("GET", token_url)

Here it reports:

Traceback (most recent call last):
  File "C:\Users\windows\Desktop\", line 35, in <module>
    conn.request("GET", token_url)
  File "C:\Python27\lib\", line 973, in request
    self._send_request(method, url, body, headers)
  File "C:\Python27\lib\", line 1001, in _send_request
    self.putrequest(method, url, **skips)
  File "C:\Python27\lib\", line 900, in putrequest
    if url.startswith('http'):
AttributeError: 'tuple' object has no attribute 'startswith'

The connection is OK, but I can't go through the following https request.


You're passing a tuple instead of a string:

>>> sig = 'sig'
>>> 'oauth/token?blahblah&' + 'sig=%s', sig
('oauth/token?blahblah&sig=%s', 'sig')
>>> 'oauth/token?blahblah&' + 'sig=%s' % sig

Replace the following line:

token_url = "oauth/token?" + urlencode(ksort(params)) + "&sig=%s",sig


token_url = "oauth/token?" + urlencode(ksort(params)) + "&sig=%s"%sig

Need Your Help

Facebook Graph API and Generic Access token

facebook facebook-graph-api oauth-2.0

If I understand correctly, the Graph API enables access to public pages using a generic access token. I'm finding however that many public pages are not returned in search results when using this t...

Adding multiple markers on Google Map with a title and position and have it change image on click

javascript google-maps google-maps-markers

Here is what I have. It doesn't work at all when I uncomment the setMarkers function. I have 75 markers to add with different titles and positions so I need an efficient way to do this. Also, each ...