Issue 545480: Examples for urllib2 (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/36459

classification

Title: Examples for urllib2
Type: Stage:
Components: Documentation Versions:

process

Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: jhylton Nosy List: fdrake, fresh, jafo, jhylton, jjlee, tim.peters
Priority: normal Keywords: patch

Created on 2002-04-18 04:13 by jafo, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (5)
msg39638 - (view) Author: Sean Reifschneider (jafo) * (Python committer) Date: 2002-04-18 04:13
An associate who's learning Python recently complained about a lack of examples for urllib2. As a starting point, I'd like to submit the following: This example gets the python.org main page and displays the first 100 bytes of it: >>> import urllib2 >>> url = urllib2.urlopen('http://www.python.org/') >>> print url.read()[:100] <!-- THIS PAGE IS AUTOMATICAL >>> Here we are sending a data-stream to the stdin of a CGI and reading the data it returns to us: >>> import urllib2 >>> req = urllib2.Request(url = 'https://localhost/cgi-bin/test.cgi', ... data = 'This data is passed to stdin of the CGI') >>> url = urllib2.urlopen(req) >>> print url.read() Got Data: "This data is passed to stdin of the CGI" >>> The code for the sample CGI used in the above example is: #!/usr/bin/env python import sys data = sys.stdin.read() print 'Content-type: text-plain\n\nGot Data: "%s"' % data
msg39639 - (view) Author: Chris Withers (fresh) Date: 2002-11-19 16:02
Logged In: YES user_id=24723 The examples for urllib2 are still really lacking :-( I want to open an http basic auth protected URL and check whether or not I get a 404 back. I have no idea hwo to do that given the current documentation...
msg39640 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2003-04-25 15:42
Logged In: YES user_id=3066 I've committed the examples from the patch in a slightly modified form to Doc/lib/liburllib2.tex revisions 1.8 and 1.6.8.2. Additional examples would be really helpful; especially demonstrating the authentication support, as noted in the comment from "fresh".
msg39641 - (view) Author: John J Lee (jjlee) Date: 2003-08-31 19:49
Logged In: YES user_id=261020 Please see 798244 -- I've uploaded some more examples there.
msg39642 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-03-21 19:34
Logged In: YES user_id=31435 Since Fred said he checked in the examples here last year, and there is no other actionable item in this patch report, closing it now.
History
Date User Action Args
2022-04-10 16:05:14 admin set github: 36459
2002-04-18 04:13:32 jafo create