Created
November 10, 2011 18:27
-
-
Save limed/1355667 to your computer and use it in GitHub Desktop.
Using PUT in urllib2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import json | |
apikey = '' | |
user = '' | |
baseurl = '' | |
query_enable = { 'is_enabled' : True } | |
query_disable = { 'is_enabled' : False, 'disabled_reason' : "infringement3" } | |
url = baseurl + user + "?key=" + apikey | |
json_data = json.dumps(query_disable) | |
opener = urllib2.build_opener(urllib2.HTTPHandler) | |
request = urllib2.Request(url, data=json_data) | |
request.add_header('Content-Type', 'application/json') | |
request.get_method = lambda: 'PUT' | |
url = opener.open(request) | |
print url.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello guys, could you please explain why we're using lamda here for get_method()?
Thanks!