", line 1, in File "/usr/local"/> ", line 1, in File "/usr/local">

Home  >  Article  >  Backend Development  >  How to solve the error reported by amqp module on python2.7.6?

How to solve the error reported by amqp module on python2.7.6?

零下一度
零下一度Original
2017-06-30 13:37:021636browse

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:

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

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:

METHOD_NAME_MAP[unpack('>I', pack('>HH', *_method_id))[0]] = \

I changed it to unicode before

METHOD_NAME_MAP[unpack(u&#39;>I&#39;, pack(u&#39;>HH&#39;, *_method_id))[0]] = \

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:

METHOD_NAME_MAP[unpack(str(&#39;>I&#39;), pack(str(&#39;>HH&#39;), *_method_id))[0]] = \

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn