I dont want to use html file, but only with django I have to make POST request. Just like urllib2 sends a get request.
django
POST requests
urllib2Â --- GET
seen from United States
seen from Japan
seen from South Korea
seen from China

seen from France
seen from China
seen from South Korea
seen from South Korea
seen from South Korea
seen from South Korea
seen from South Korea

seen from Syria
seen from South Korea
seen from South Korea
seen from China

seen from Finland

seen from United States
seen from South Korea
seen from France
seen from Italy
I dont want to use html file, but only with django I have to make POST request. Just like urllib2 sends a get request.
django
POST requests
urllib2Â --- GET

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
From: https://docs.python.org/2/howto/urllib2.html
Also Cool:
import urllib import urllib2 url = 'http://www.someserver.com/cgi-bin/register.cgi' user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' values = {'name' : 'Michael Foord', Â Â Â Â Â 'location' : 'Northampton', Â Â Â Â Â 'language' : 'Python' } headers = { 'User-Agent' : user_agent } data = urllib.urlencode(values) req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) the_page = response.read()
Fixed Should I use urllib or urllib2 or requests? #dev #it #asnwer
Fixed Should I use urllib or urllib2 or requests? #dev #it #asnwer
Should I use urllib or urllib2 or requests?
In Python (2.5), should I use urllib or urllib2 or requests? What’s the difference? They seem to do the same thing.
Answer: Should I use urllib or urllib2 or requests?
urllib2.urlopen accepts an instance of the Request class or a url, whereas urllib.urlopen only accepts a url.
A similar discussion took place here: http://www.velocityreviews.com/forums…
View On WordPress
Fixed How do I download a file over HTTP using Python? #dev #it #asnwer
Fixed How do I download a file over HTTP using Python? #dev #it #asnwer
How do I download a file over HTTP using Python?
I have a small utility that I use to download an MP3 from a website on a schedule and then builds/updates a podcast XML file which I’ve obviously added to iTunes.
The text processing that creates/updates the XML file is written in Python. I use wget inside a Windows .bat file to download the actual MP3 however. I would prefer to have the entire…
View On WordPress
How to: Should I use urllib or urllib2 or requests?
How to: Should I use urllib or urllib2 or requests?
Should I use urllib or urllib2 or requests?
In Python (2.5), should I use urllib or urllib2 or requests? What’s the difference? They seem to do the same thing.
Answer: Should I use urllib or urllib2 or requests?
urllib2.urlopen accepts an instance of the Request class or a url, whereas urllib.urlopen only accepts a url.
A similar discussion took place here: http://www.velocityreviews.com/forums…
View On WordPress

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
How to: How do I download a file over HTTP using Python?
How to: How do I download a file over HTTP using Python?
How do I download a file over HTTP using Python?
I have a small utility that I use to download an MP3 from a website on a schedule and then builds/updates a podcast XML file which I’ve obviously added to iTunes.
The text processing that creates/updates the XML file is written in Python. I use wget inside a Windows .bat file to download the actual MP3 however. I would prefer to have the entire…
View On WordPress
Simple HTTP handling with urllib2
I am continuing to poke around python this week looking the "standard way" to make HTTP requests and process HTTP responses. In Perl, there is the very complete LWP set of modules. In Java, there is the Apache HTTP client library. Python has several modules with related functionality, including httplib, urllib and urllib2 (which will change with Python 3.0).
What I need to do is create HTTP headers in the request and later read headers from the response. Oh, and I will want to look at the response's body too.
The code below makes an HTTP to a small PHP script I have on this server (use it as needed). It sets a header, which is echoed by the PHP script. Later all the headers from the response are also echoed.
One of the things I like about urllib2 is the Request class. In the things I want to do (web services, OAuth), it is very helpful to build the request and be able to inspect it apart from the mechanism that performs the HTTP fetch.
import urllib2 import pprint import sys url = "http://taskboy.com/blog/h.php" R = urllib2.Request(url) R.add_header("User-agent", "jjohn/1.0") try : f = urllib2.urlopen(R) headers = f.info().headers c = f.read() # content except : e = sys.exc_info()[0] print "Oops: ", e exit; print "Content: " + c + "\n" print "HEADERS: "; for k in headers : print "'" + k + "'"
Basic Authentication in bottle.py
I've been using bottle.py a lot recently to quickly write REST-like APIs. I say 'REST-like' because at the moment they mostly only satisfy GET requests. Up until now actually. Now I want to write a full REST interface with support for GET, POST, PUT and DELETE.
As part of this I need the most basic of basic authentication on my server. I want to put a password on my POST, PUT and DELETE requests. I had a look at bottle-cork but it seemed overkill for what I needed. Digging into the bottle.py source code I found this little gem of a decorator called auth_basic(). So here is how you use it:
import bottle def check(user, passwd): if user == 'ben': return True return False @bottle.route('/') @bottle.auth_basic(check) def index(location): print 'auth', bottle.request.auth print 'remote_addr', bottle.request.remote_addr return "Yay - you made it!" if __name__ == '__main__': print "Starting server" bottle.run(host='0.0.0.0', port=8080, reloader=True)
That is a pretty simple demonstration. If you attempt to go to the page in a browser you will get a 401 Error back. To access the page in python, use this little code snippit from StackOverflow:
import urllib2, base64 (user, password) = ('ben', 'xyz') request = urllib2.Request("http://localhost:8080/") base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') request.add_header("Authorization", "Basic %s" % base64string) result = urllib2.urlopen(request) print result.read()Â
And you should see "Yay - you made it" printed out.
I hope this tiny simple little code example will help someone out in the future so they don't have to go digging for information like this.