Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
53e5b71b
Commit
53e5b71b
authored
Apr 25, 2003
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add modified versions of the examples from Sean Reifschneider
(SF patch #545480).
parent
b016752d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
Doc/lib/liburllib2.tex
Doc/lib/liburllib2.tex
+36
-0
No files found.
Doc/lib/liburllib2.tex
View file @
53e5b71b
...
...
@@ -601,3 +601,39 @@ Open the gopher resource indicated by \var{req}.
\begin{methoddesc}
[UnknownHandler]
{
unknown
_
open
}{}
Raise a
\exception
{
URLError
}
exception.
\end{methoddesc}
\subsection
{
Examples
\label
{
urllib2-examples
}}
This example gets the python.org main page and displays the first 100
bytes of it:
\begin{verbatim}
>>> import urllib2
>>> f = urllib2.urlopen('http://www.python.org/')
>>> print f.read(100)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?xml-stylesheet href="./css/ht2html
\end{verbatim}
Here we are sending a data-stream to the stdin of a CGI and reading
the data it returns to us:
\begin{verbatim}
>>> import urllib2
>>> req = urllib2.Request(url='https://localhost/cgi-bin/test.cgi',
... data='This data is passed to stdin of the CGI')
>>> f = urllib2.urlopen(req)
>>> print f.read()
Got Data: "This data is passed to stdin of the CGI"
\end{verbatim}
The code for the sample CGI used in the above example is:
\begin{verbatim}
#!/usr/bin/env python
import sys
data = sys.stdin.read()
print 'Content-type: text-plain
\n\nGot
Data: "
%s"' %
data
\end{verbatim}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment