Goomba Stomp Goomba Stomp - 8 months ago 69
Python Question

TypeError: unhashable type in python script using urllib

I'm attempting to execute the following curl command in a python script using urllib:

curl -H "token:<COMPANY_TOKEN>" -X PUT \

Here's what I have in Python:

import urllib
import urllib2

theToken = <TOKEN>
headers = {"token":theToken}

checkOutUrl = "https://<DOMAIN><ASSET_ID>/checkout.api?user_id=<USER_ID>"

req = urllib2.Request(checkOutUrl, headers)
response = urllib2.urlopen(req)
thePage =

I understand this particular error will come up without the following:

data = urllib.urlencode(values)

but this command has no data and works fine from a shell prompt.


You are trying to pass off the headers as the request body, the data argument. Don't pass those headers in as a positional argument, use a keyword argument instead:

req = urllib2.Request(checkOutUrl, headers=headers)