[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2021-11-30 Thread Irit Katriel


Irit Katriel  added the comment:

Reproduced on 3.11:

>>> from urllib.request import urlopen
>>> try:
... urlopen('http://www.pythonfoobarbaz.org')
... except Exception as exc:
... err = exc
... print('err:', err)
... print('repr(err):', repr(err))
... print('err.errno:', err.errno)
... print('err.strerror:', err.strerror)
... print('err.reason:', err.reason)
... print('err.reason.errno:', err.reason.errno)
... print('err.reason.strerror:', err.reason.strerror)
... 
err: 
repr(err): URLError(gaierror(8, 'nodename nor servname provided, or not known'))
err.errno: None
err.strerror: None
err.reason: [Errno 8] nodename nor servname provided, or not known
err.reason.errno: 8
err.reason.strerror: nodename nor servname provided, or not known

--
nosy: +iritkatriel
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 2.6, Python 2.7, Python 
3.1, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2013-07-29 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
nosy: +denkoren

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2012-09-19 Thread Ezio Melotti

Ezio Melotti added the comment:

 I seem to remember writing code that fished the wrapped error
 out using one of those attributrs...

That would be err.reason:

from urllib.request import urlopen
try:
urlopen('http://www.pythonfoobarbaz.org')
except Exception as exc:
print('err:', err)
print('repr(err):', repr(err))
print('err.reason:', err.reason)
print('repr(err.reason):', repr(err.reason))

prints:

err: urlopen error [Errno -2] Name or service not known
repr(err): URLError(gaierror(-2, 'Name or service not known'),)
err.reason: [Errno -2] Name or service not known
repr(err.reason): gaierror(-2, 'Name or service not known')

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2012-09-19 Thread Chris Jerdonek

Changes by Chris Jerdonek chris.jerdo...@gmail.com:


--
nosy: +cjerdonek

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2012-09-19 Thread R. David Murray

R. David Murray added the comment:

Ah, of course.  I should have reread the whole issue :)

The backward compatibility is the big concern here.  Regardless of what we do 
about that, we should at least fix this in 3.4.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2012-08-03 Thread R. David Murray

R. David Murray added the comment:

This is an interesting idea and should at least improve matters.  I'm 
wondering, though...I seem to remember writing code that fished the wrapped 
error out using one of those attributrs...but I'm not at a computer where I can 
try to check on that.  Hopefully I can check on it this weekend.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2012-07-28 Thread Catherine Devlin

Catherine Devlin added the comment:

It's very hard to tell what ought to be done here, since Lib/urllib/request.py 
throws URLErrors with a great variety of order and number of arguments, and 
it's not clear how URLError (in Lib/urllib/error.py) intends to handle them.

However, in this case, AbstractHTTPHandler.do_open is instantiating URLError 
with another exception instance, and that exception contains .errno and 
.strerror.  URLError puts the entire error instance into ``reason``, where the 
information is hidden away as .reason.strno and .reason.strerror. 

In the name of keeping this information available rather than hiding it, I'm 
attaching a patch that adds to URLError.__init__:

if hasattr(reason, errno):
self.errno = reason.errno
if hasattr(reason, strerror):
self.strerror = reason.strerror

Again, I'm not sure this is the most logical approach because I can't find a 
consistent pattern in the ways URLError is instantiated.

--
keywords: +patch
nosy: +catherine
Added file: http://bugs.python.org/file26559/keeperrdata.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2010-02-27 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

Can this be fixed without breaking compatibility?
It also affects Python2.7 and maybe also Python 3.x (there the error is 
different and might be intentional).

Copy/pastable snippet to reproduce the error on 2.x:
from urllib import urlopen
try:
urlopen('http://www.pythonfoobarbaz.org')
except Exception, err:
print 'err:', err
print 'repr(err):', repr(err)
print 'err.errno:', err.errno
print 'err.strerror:', err.strerror
print 'err.strerror.errno:', err.strerror.errno
print 'err.strerror.strerror:', err.strerror.strerror

Result on 2.7:
err: [Errno socket error] [Errno -2] Name or service not known
repr(err): IOError('socket error', gaierror(-2, 'Name or service not known'))
err.errno: socket error
err.strerror: [Errno -2] Name or service not known
err.strerror.errno: -2
err.strerror.strerror: Name or service not known


Copy/pastable snippet to reproduce the error on 3.x:
from urllib.request import urlopen
try:
urlopen('http://www.pythonfoobarbaz.org')
except Exception as exc:
err = exc
print('err:', err)
print('repr(err):', repr(err))
print('err.errno:', err.errno)
print('err.strerror:', err.strerror)
print('err.reason:', err.reason)
print('err.reason.errno:', err.reason.errno)
print('err.reason.strerror:', err.reason.strerror)

Result on 3.2:
err: urlopen error [Errno -2] Name or service not known
repr(err): URLError(gaierror(-2, 'Name or service not known'),)
err.errno: None
err.strerror: None
err.reason: [Errno -2] Name or service not known
err.reason.errno: -2
err.reason.strerror: Name or service not known

--
nosy: +orsenthil
stage:  - needs patch
versions: +Python 2.7, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6471] errno and strerror attributes incorrectly set on socket errors wrapped by urllib

2009-07-12 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
title: errno and strerror attributes incorrectly set on socket.error - errno 
and strerror attributes incorrectly set on socket errors wrapped by urllib

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6471
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com