Public bug reported:

A script my team uses python3-amqplib for RabbitMQ connectivity
checking, but in the case of not being able to connect, the error we get
when running from Python 3 hides the real problem behind a Python 3
variable scoping issue.

This is reproducible via: python3 -c "from amqplib import client_0_8 as
amqp; amqp.Connection()"

The above will generate this output (assuming no RabbitMQ is running on
your system):

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/amqplib/client_0_8/connection.py", line 
129, in __init__
    self.transport = create_transport(host, connect_timeout, ssl)
  File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
281, in create_transport
    return TCPTransport(host, connect_timeout)
  File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
85, in __init__
    raise socket.error(msg)
UnboundLocalError: local variable 'msg' referenced before assignment

I would instead expect the following, which I see on Bionic when running
the same command from above, but via Python 2 instead:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/connection.py", 
line 129, in __init__
    self.transport = create_transport(host, connect_timeout, ssl)
  File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", line 
281, in create_transport
    return TCPTransport(host, connect_timeout)
  File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", line 
85, in __init__
    raise socket.error, msg
socket.error: [Errno 111] Connection refused

In Python 2, we get "Connection refused" - in Python 3, we get a Python
error, which hides the "Connection refused" message.

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: python3-amqplib (not installed)
ProcVersionSignature: Ubuntu 5.4.0-47.51-generic 5.4.55
Uname: Linux 5.4.0-47-generic x86_64
NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair
ApportVersion: 2.20.11-0ubuntu27.8
Architecture: amd64
CasperMD5CheckResult: skip
CurrentDesktop: ubuntu:GNOME
Date: Wed Sep 16 14:08:00 2020
InstallationDate: Installed on 2019-01-04 (621 days ago)
InstallationMedia: Ubuntu 18.10 "Cosmic Cuttlefish" - Release amd64 (20181017.3)
SourcePackage: python-amqplib
UpgradeStatus: Upgraded to focal on 2020-01-31 (229 days ago)

** Affects: python-amqplib (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug focal

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1895893

Title:
  Python 3 variable scoping issue is hiding error tracebacks

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-amqplib/+bug/1895893/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to