{"action":"opened","issue":{"url":"https://api.github.com/repos/singularityware/singularity/issues/664","repository_url":"https://api.github.com/repos/singularityware/singularity","labels_url":"https://api.github.com/repos/singularityware/singularity/issues/664/labels{/name}","comments_url":"https://api.github.com/repos/singularityware/singularity/issues/664/comments","events_url":"https://api.github.com/repos/singularityware/singularity/issues/664/events","html_url":"https://github.com/singularityware/singularity/issues/664","id":227346333,"number":664,"title":"`urllib` module dependencies for Python 3","user":{"login":"ashiklom","id":5680221,"avatar_url":"https://avatars3.githubusercontent.com/u/5680221?v=3","gravatar_id":"","url":"https://api.github.com/users/ashiklom","html_url":"https://github.com/ashiklom","followers_url":"https://api.github.com/users/ashiklom/followers","following_url":"https://api.github.com/users/ashiklom/following{/other_user}","gists_url":"https://api.github.com/users/ashiklom/gists{/gist_id}","starred_url":"https://api.github.com/users/ashiklom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashiklom/subscriptions","organizations_url":"https://api.github.com/users/ashiklom/orgs","repos_url":"https://api.github.com/users/ashiklom/repos","events_url":"https://api.github.com/users/ashiklom/events{/privacy}","received_events_url":"https://api.github.com/users/ashiklom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-09T12:18:11Z","updated_at":"2017-05-09T12:18:11Z","closed_at":null,"body":"The `docker` module will fail when using current Python 3 (which is the [default `python` executable on Arch Linux](https://wiki.archlinux.org/index.php/python), and it seems other distributions are [moving in this direction as well](https://wiki.ubuntu.com/Python)) with the following error:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/libexec/singularity/python/cli.py\", line 27, in <module>\r\n    from docker.api import get_layer, create_runscript, get_manifest, get_config, get_images\r\n  File \"/usr/libexec/singularity/python/docker/api.py\", line 29, in <module>\r\n    from utils import api_get, write_file, add_http\r\n  File \"/usr/libexec/singularity/python/utils.py\", line 32, in <module>\r\n    import urllib2\r\nModuleNotFoundError: No module named 'urllib2'\r\n```\r\n\r\nThis is because the `urllib2` module has been [deprecated in Python 3](https://docs.python.org/2/library/urllib2.html).\r\n\r\nFortunately, this is easily fixed by running `2to3` on the `/usr/libexec/singularity/utils.py` script. I've provided the diff output from `2to3 utils.py` below.\r\n\r\n```\r\n--- utils.py    (original)\r\n+++ utils.py    (refactored)\r\n@@ -28,10 +28,10 @@\r\n import subprocess\r\n import sys\r\n import tarfile\r\n-import urllib\r\n-import urllib2\r\n-\r\n-from urllib2 import HTTPError\r\n+import urllib.request, urllib.parse, urllib.error\r\n+import urllib.request, urllib.error, urllib.parse\r\n+\r\n+from urllib.error import HTTPError\r\n\r\n # Python less than version 3 must import OSError\r\n if sys.version_info[0] < 3:\r\n@@ -74,7 +74,7 @@\r\n        try:\r\n            response = json.loads(response)\r\n        except:\r\n-           print(\"Error parsing response for url %s, exiting.\" %(url))\r\n+           print((\"Error parsing response for url %s, exiting.\" %(url)))\r\n            sys.exit(1)\r\n\r\n        # If we have a next url\r\n@@ -128,16 +128,16 @@\r\n         do_stream = True\r\n\r\n     if data != None:\r\n-        args = urllib.urlencode(data)\r\n-        request = urllib2.Request(url=url,\r\n+        args = urllib.parse.urlencode(data)\r\n+        request = urllib.request.Request(url=url,\r\n                                   data=args,\r\n                                   headers=headers)\r\n     else:\r\n-        request = urllib2.Request(url=url,\r\n+        request = urllib.request.Request(url=url,\r\n                                   headers=headers)\r\n\r\n     try:\r\n-        response = urllib2.urlopen(request)\r\n+        response = urllib.request.urlopen(request)\r\n\r\n     # If we have an HTTPError, try to follow the response\r\n     except HTTPError as error:\\\r\n```"}}
{"actor":{"display_login":"ashiklom"}}