0

urllib fetches data from urls right? is there a python library that can do the reverse of that and send data to urls instead (for example, to a site you are managing)? and if so, is that library compatible with apache?

thanks.

0

2 Answers 2

6

What does sending data to a URL mean? The usual way to do that is just via an HTTP POST, and urllib (and urllib2) handle that just fine.

3
  • forgive me i am new to the world of web design. what little i know of urllib tells me that you can get data from forms etc. so what i meant by "sending data to a URL" is the capability to then supply data to forms. url can handle this too, i guess?
    – user582485
    Mar 1, 2011 at 19:38
  • urllib and urllib2 can post form data but it can get a bit tedious. If you're trying to fill out web forms and/or emulate a human user, I'd recommend taking a look at mechanize. Mar 1, 2011 at 19:45
  • @Marc Correct me if I'm wrong, but when a page submits a form, it's usually over a simple get/post request, right? Why would this be difficult to do with urllib/urllib2?
    – Wilduck
    Mar 1, 2011 at 19:58
2

urllib can send data associated with a request by using GET or POST.

urllib2.urlopen(url, data) where data is a dict of key-values representing the data you're sending. See this link on usage. Then process that data on the server-side.

If you want to send data any other way, you should use some other protocol such as FTP (see ftplib).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.