diff mbox series

scipts/autobuild-run: properly import urllib2.URLError

Message ID 20210605210016.1157351-1-yann.morin.1998@free.fr
State Accepted
Headers show
Series scipts/autobuild-run: properly import urllib2.URLError | expand

Commit Message

Yann E. MORIN June 5, 2021, 9 p.m. UTC
Commit 37766e9 (scripts/autobuild-run: add a retry loop to not fail on
urllib URLError) introduced an import of URLError, but that raises
exceptions in both python2 and python3:

    $ python2 -c 'import urllib2.URLError as URLError'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named URLError

    $ python3 -c 'import urllib.error.URLError as URLError'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'urllib.error.URLError'; 'urllib.error' is not a package

The working solution is to import from:

    $ python2 -c 'from urllib2 import URLError; raise URLError(None)'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    urllib2.URLError: <urlopen error None>

    $ python3 -c 'from urllib.error import URLError; raise URLError(None)'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    urllib.error.URLError: <urlopen error None>

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 scripts/autobuild-run | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Thomas Petazzoni June 5, 2021, 9:05 p.m. UTC | #1
On Sat,  5 Jun 2021 23:00:16 +0200
"Yann E. MORIN" <yann.morin.1998@free.fr> wrote:

> Commit 37766e9 (scripts/autobuild-run: add a retry loop to not fail on
> urllib URLError) introduced an import of URLError, but that raises
> exceptions in both python2 and python3:
> 
>     $ python2 -c 'import urllib2.URLError as URLError'
>     Traceback (most recent call last):
>       File "<string>", line 1, in <module>
>     ImportError: No module named URLError
> 
>     $ python3 -c 'import urllib.error.URLError as URLError'
>     Traceback (most recent call last):
>       File "<string>", line 1, in <module>
>     ModuleNotFoundError: No module named 'urllib.error.URLError'; 'urllib.error' is not a package
> 
> The working solution is to import from:
> 
>     $ python2 -c 'from urllib2 import URLError; raise URLError(None)'
>     Traceback (most recent call last):
>       File "<string>", line 1, in <module>
>     urllib2.URLError: <urlopen error None>
> 
>     $ python3 -c 'from urllib.error import URLError; raise URLError(None)'
>     Traceback (most recent call last):
>       File "<string>", line 1, in <module>
>     urllib.error.URLError: <urlopen error None>
> 
> Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

Thanks!

Thomas
Yann E. MORIN June 6, 2021, 7:20 a.m. UTC | #2
All,

On 2021-06-05 23:05 +0200, Thomas Petazzoni spake thusly:
> On Sat,  5 Jun 2021 23:00:16 +0200
> "Yann E. MORIN" <yann.morin.1998@free.fr> wrote:
> > Commit 37766e9 (scripts/autobuild-run: add a retry loop to not fail on
> > urllib URLError) introduced an import of URLError, but that raises
> > exceptions in both python2 and python3:
[--SNIP--]
> > The working solution is to import from:
[--SNIP--]
> > Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
> > Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

Applied to master (on buildroot-test), thanks.

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/scripts/autobuild-run b/scripts/autobuild-run
index 84e4d40..346928f 100755
--- a/scripts/autobuild-run
+++ b/scripts/autobuild-run
@@ -151,12 +151,12 @@  if sys.hexversion >= 0x3000000:
     import configparser
     import urllib.request as _urllib
     import urllib.parse as urlparse
-    import urllib.error.URLError as URLError
+    from urllib.error import URLError
 else:
     import ConfigParser as configparser
     import urllib2 as _urllib
     import urlparse
-    import urllib2.URLError as URLError
+    from urllib2 import URLError
 
 urlopen = _urllib.urlopen
 urlopen_closing = lambda uri: contextlib.closing(urlopen(uri))