add-apt-repository crashed with AttributeError in _get_https_content_py3(): 'InvalidURL' object has no attribute 'reason'

Bug #1871006 reported by Pablo
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
software-properties (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

Release: 20.04 Ubuntu Focal Fossa (development branch)
Package/Program: add-apt-repository
Command:
$ sudo add-apt-repository --remove ppa:"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Expected response:
 Either to get the ppa removed or the exception handled with a message "unable to find the URL"

What happened instead:
 The traceback of an exception was printed in the terminal.

Traceback:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 138, in _get_https_content_py3
    lp_page = urllib.request.urlopen(request,
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 1362, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/usr/lib/python3.8/urllib/request.py", line 1319, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.8/http/client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1241, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/lib/python3.8/http/client.py", line 1092, in putrequest
    self._validate_path(url)
  File "/usr/lib/python3.8/http/client.py", line 1183, in _validate_path
    raise InvalidURL(f"URL can't contain control characters. {url!r} "
http.client.InvalidURL: URL can't contain control characters. '/api/devel/~deb [arch=amd64] https/+archive/ubuntu/ppa' (found at least ' ')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 380, in get_ppa_info
    ret = get_ppa_info_from_lp(user, ppa)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 110, in get_ppa_info_from_lp
    return get_info_from_lp(lp_url)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 104, in get_info_from_lp
    return get_info_from_https(lp_url, True)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 96, in get_info_from_https
    data = func(lp_url=url, accept_json=accept_json, retry_delays=retry_delays)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 143, in _get_https_content_py3
    "Error reading %s (%d tries): %s" % (lp_url, trynum, e.reason),
AttributeError: 'InvalidURL' object has no attribute 'reason'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 138, in _get_https_content_py3
    lp_page = urllib.request.urlopen(request,
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 1362, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/usr/lib/python3.8/urllib/request.py", line 1319, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.8/http/client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1241, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/lib/python3.8/http/client.py", line 1092, in putrequest
    self._validate_path(url)
  File "/usr/lib/python3.8/http/client.py", line 1183, in _validate_path
    raise InvalidURL(f"URL can't contain control characters. {url!r} "
http.client.InvalidURL: URL can't contain control characters. '/api/1.0/~deb [arch=amd64] https' (found at least ' ')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 136, in <module>
    shortcut = shortcut_handler(line)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 871, in shortcut_handler
    ret = factory(shortcut)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 469, in shortcut_handler
    return PPAShortcutHandler(shortcut)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 426, in __init__
    info = get_ppa_info(self.shortcut)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 392, in get_ppa_info
    _get_suggested_ppa_message(user, ppa))
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 349, in _get_suggested_ppa_message
    lp_user = get_info_from_lp(LAUNCHPAD_USER_API % user)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 104, in get_info_from_lp
    return get_info_from_https(lp_url, True)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 96, in get_info_from_https
    data = func(lp_url=url, accept_json=accept_json, retry_delays=retry_delays)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 143, in _get_https_content_py3
    "Error reading %s (%d tries): %s" % (lp_url, trynum, e.reason),
AttributeError: 'InvalidURL' object has no attribute 'reason'

ProblemType: Crash
DistroRelease: Ubuntu 20.04
Package: software-properties-common 0.98.7
ProcVersionSignature: Ubuntu 5.4.0-21.25-generic 5.4.27
Uname: Linux 5.4.0-21-generic x86_64
NonfreeKernelModules: nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu22
Architecture: amd64
Date: Mon Apr 6 01:38:30 2020
ExecutablePath: /usr/bin/add-apt-repository
InstallationDate: Installed on 2020-04-05 (0 days ago)
InstallationMedia: Ubuntu 20.04 LTS "Focal Fossa" - Beta amd64 (20200401)
InterpreterPath: /usr/bin/python3.8
PackageArchitecture: all
ProcCmdline: /usr/bin/python3 /usr/bin/add-apt-repository --remove ppa:deb\ [arch=amd64]\ https://download.docker.com/linux/ubuntu\ focal\ stable
ProcEnviron:
 LANGUAGE=en_GB:en
 LANG=en_GB.UTF-8
 TERM=xterm-256color
 PATH=(custom, no user)
 SHELL=/bin/bash
Python3Details: /usr/bin/python3.8, Python 3.8.2, python3-minimal, 3.8.2-0ubuntu2
PythonArgs: ['/usr/bin/add-apt-repository', '--remove', 'ppa:deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable']
PythonDetails: N/A
SourcePackage: software-properties
Title: add-apt-repository crashed with AttributeError in _get_https_content_py3(): 'InvalidURL' object has no attribute 'reason'
UpgradeStatus: No upgrade log present (probably fresh install)
UserGroups:

Revision history for this message
Pablo (alunt) wrote :
tags: removed: need-duplicate-check
Changed in software-properties (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thank you for your bug report. The command should take the name of the ppa to remove, how did you use it exactly?

information type: Private → Public
Changed in software-properties (Ubuntu):
status: New → Incomplete
Revision history for this message
Pablo (alunt) wrote :

Hi Sebastien,

I used exactly the same command I used to add the ppa, except that I added the flag --remove. Here is the command:

sudo add-apt-repository --remove ppa:"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

The thing here is that, even if the command had the wrong parameter (which seems to be the case), the exception should still be caught and a proper error message be shown, shouldn't it?

The command to add this ppa (without the --remove flag) has been taken from the official Docker page.

In addition to this error, I found that, having this ppa (which could not be found due to Docker not having released the related version to "focal"), when doing a refresh from the Software & Updates package, it fails showing the Report Bug window and freezes, not letting the user to close it. I guess this bug would appear with any ppa that cannot be found.

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, indeed that command triggers the error

Changed in software-properties (Ubuntu):
status: Incomplete → Confirmed
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.