Skip to contentSkip to conversation

scipts/autobuild-run: properly import urllib2.URLError

PATCH New Yann E. MORIN 2 participants 3 messages Jun 5, 2021 – Jun 6, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scipts/autobuild-run: properly import urllib2.URLError

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>
Cc Thomas Petazzoni <[email protected]>
---
 scripts/autobuild-run | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/autobuild-run +2 -2
index 84e4d40..346928f 100755
@@ -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))
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 scipts/autobuild-run: properly import urllib2.URLError

Quoted 21 lines · On Sat, 5 Jun 2021 23:00:16 +0200 "Yann E. MORIN" <[email protected]>…

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>
Quoted 7 lines
    $ 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>
Cc Thomas Petazzoni <[email protected]>

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 scipts/autobuild-run: properly import urllib2.URLError

All,

On 2021-06-05 23:05 +0200, Thomas Petazzoni spake thusly:

Quoted 5 lines
Quoted 3 lines · On Sat, 5 Jun 2021 23:00:16 +0200 "Yann E. MORIN" <[email protected]>…

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--]

Quoted 1 line
Quoted 1 line

The working solution is to import from:

[--SNIP--]

Quoted 3 lines
Quoted 2 lines
Cc Thomas Petazzoni <[email protected]>

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

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'