-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-130283: update deprecated links and examples in urllib.request
docs
#130284
base: main
Are you sure you want to change the base?
gh-130283: update deprecated links and examples in urllib.request
docs
#130284
Conversation
@sobolevn PTAL |
>>> f = urllib.request.urlopen('http://www.python.org/') | ||
>>> print(f.read(100).decode('utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> f = urllib.request.urlopen('http://www.python.org/') | |
>>> print(f.read(100).decode('utf-8')) | |
>>> with urllib.request.urlopen('http://www.python.org/') as f: | |
... print(f.read(100).decode('utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also use with
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sobolevn It is the example without using the context manager approach.
|
||
Note that urlopen returns a bytes object. This is because there is no way | ||
for urlopen to automatically determine the encoding of the byte stream | ||
it receives from the HTTP server. In general, a program will decode | ||
the returned bytes object to string once it determines or guesses | ||
the appropriate encoding. | ||
|
||
The following W3C document, https://www.w3.org/International/O-charset\ , lists | ||
the various ways in which an (X)HTML or an XML document could have specified its | ||
The following W3C document, https://www.w3.org/International/questions/qa-html-encoding-declarations\ , lists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need small suggestion here, as https://www.w3.org/International/O-charset is deprecated by W3C, and it added these two suggestions in the page
You may want to try, instead, one of the following pages:
Handling character encodings in HTML and CSS (tutorial)
Declaring character encodings in HTML
I've added https://www.w3.org/International/questions/qa-html-encoding-declarations this one but we can add something other instead of this like
- https://www.w3.org/International/questions/qa-what-is-encoding
- https://www.w3.org/International/getting-started/characters
or any other.
I would love to know the thought's of the fellow dev's.
>>> f = urllib.request.urlopen('http://www.python.org/') | ||
>>> print(f.read(100).decode('utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sobolevn It is the example without using the context manager approach.
"http://www.w3.org/TR/xhtml1/DTD/xhtm | ||
<!doctype html> | ||
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]--> | ||
<!- | ||
|
||
It is also possible to achieve the same result without using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref. @sobolevn
fix: #130283
📚 Documentation preview 📚: https://cpython-previews--130284.org.readthedocs.build/