", line 1, in Home >Backend Development >Python Tutorial >How to solve the error reported by amqp module on python2.7.6? The environment of the machine is python2.7.6; I installed amqp using pip install. It was installed normally and no error was reported. The installed version of amqp is 2.1.4. In python, when using import amqp, the error is as follows: Baidu and Google have some Struct() argument 1 must be string, not unicode related content , slightly useful is the discussion on github When I saw this version of the code followed the example and changed the corresponding places to uncoded form , that is, adding u'' in front of the string. did not solve the problem After repeated review, I finally thought about it, opened the file where the error was reported earlier, and looked at it. In line 298, _method_name The previous line is: I changed it to unicode before Because this is how it was changed on github, without any thought at all Just copy it In fact, just change it to the following: You won’t get an error if you use import amqp again Think about it later , it is clearly stated in the error report that you need a string, so just follow it, but if you don’t think carefully, you will repeatedly struggle with unicode and take too many detours. The first time you encounter an error, you have to change the source in the python library The code is also drunk, so I will reluctantly record it. The above is the detailed content of How to solve the error reported by amqp module on python2.7.6?. For more information, please follow other related articles on the PHP Chinese website!How to solve the error reported by amqp module on python2.7.6?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/amqp/__init__.py", line 45, in <module>
from .basic_message import Message # noqa
File "/usr/local/lib/python2.7/site-packages/amqp/basic_message.py", line 29, in <module>
from .serialization import GenericContent
File "/usr/local/lib/python2.7/site-packages/amqp/serialization.py", line 31, in <module>
from .exceptions import FrameSyntaxError
File "/usr/local/lib/python2.7/site-packages/amqp/exceptions.py", line 298, in <module>
_method_name
TypeError: Struct() argument 1 must be string, not unicode
METHOD_NAME_MAP[unpack('>I', pack('>HH', *_method_id))[0]] = \
METHOD_NAME_MAP[unpack(u'>I', pack(u'>HH', *_method_id))[0]] = \
METHOD_NAME_MAP[unpack(str('>I'), pack(str('>HH'), *_method_id))[0]] = \