This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib.request.thishost() returns a garbage value
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: deokhwan.kim, ezio.melotti, orsenthil, python-dev, skrah, vstinner
Priority: normal Keywords: patch

Created on 2011-10-04 23:02 by deokhwan.kim, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
thishost.patch deokhwan.kim, 2011-10-04 23:02
Messages (6)
msg144929 - (view) Author: Deokhwan Kim (deokhwan.kim) Date: 2011-10-04 23:02
There is a minor typo in Lib/urllib/request.py:thishost(). Because of it, the thishost() function is returning a garbage value:

  >>> import urllib.request
  >>> urllib.request.thishost()
  ('XXXXXXX.XXXXX.XXX.com', ['X.XXXXX.XXX.com'], ['123.45.67.89'])

It is expected to return the IP addresses of the current host, so the correct return value would be like:

  >>> urllib.request.thishost.__doc__
  'Return the IP addresses of the current host.'
  >>> urllib.request.thishost()
  ('127.0.0.1', '127.0.1.1')

The attached patch will fix the mistake .
msg144956 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-10-05 16:33
New changeset 805a0a1e3c2b by Senthil Kumaran in branch '3.2':
Issue13104 - Fix urllib.request.thishost() utility function.
http://hg.python.org/cpython/rev/805a0a1e3c2b

New changeset a228e59ad693 by Senthil Kumaran in branch 'default':
merge from 3.2.  Issue13104 - Fix urllib.request.thishost() utility function.
http://hg.python.org/cpython/rev/a228e59ad693
msg144957 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-10-05 16:34
Thanks for the report. This is fixed now. I hope in 3.3 I remove this old utility functions. (real soon).
msg144981 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-10-06 00:52
There is a failure on FreeBSD 8.2 buildbot:

http://www.python.org/dev/buildbot/all/builders/AMD64%20FreeBSD%208.2%203.x/builds/1104/steps/test/logs/stdio

======================================================================
ERROR: test_thishost (test.test_urllib.Utility_Tests)
Test the urllib.request.thishost utility function returns a tuple
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_urllib.py", line 1063, in test_thishost
    self.assertIsInstance(urllib.request.thishost(), tuple)
  File "/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/urllib/request.py", line 2128, in thishost
    _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
socket.gaierror: [Errno 8] hostname nor servname provided, or not known
msg144983 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-10-06 02:36
hmm. interesting case in FreeBSD. Looks like socket.gethostname() did not return the hostname in freebsd buildbot.
msg144985 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-10-06 07:22
/etc/hosts was incomplete; works fine now. Closing again.
History
Date User Action Args
2022-04-11 14:57:22adminsetgithub: 57313
2011-10-06 07:22:31skrahsetstatus: open -> closed
resolution: fixed
messages: + msg144985

stage: test needed -> resolved
2011-10-06 06:58:39skrahsetnosy: + skrah
2011-10-06 06:58:23skrahlinkissue13108 superseder
2011-10-06 02:36:05orsenthilsetmessages: + msg144983
2011-10-06 00:52:26vstinnersetstatus: closed -> open
resolution: fixed -> (no value)
2011-10-06 00:52:16vstinnersetnosy: + vstinner
messages: + msg144981
2011-10-05 16:34:05orsenthilsetstatus: open -> closed
assignee: orsenthil
resolution: fixed
messages: + msg144957
2011-10-05 16:33:08python-devsetnosy: + python-dev
messages: + msg144956
2011-10-05 04:28:16ezio.melottisetnosy: + ezio.melotti

stage: patch review -> test needed
2011-10-05 00:09:09ned.deilysetnosy: + orsenthil
stage: patch review

versions: + Python 3.3
2011-10-04 23:02:51deokhwan.kimcreate