学习python使用rabbitmq,遇到麻烦


学习使用rabbitmq,遇到麻烦

  • python3.3.2
  • rabbitmq3.4.1
  • pika-0.9.14

python send.py


 Traceback (most recent call last):
  File "send.py", line 3, in <module>
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
  File "/home/hawk/g/sqlalchemy/lib/python3.3/site-packages/pika/connection.py", line 361, in __init__
    if host and self._validate_host(host):
  File "/home/hawk/g/sqlalchemy/lib/python3.3/site-packages/pika/connection.py", line 207, in _validate_host
    if not isinstance(host, basestring):
NameError: global name 'basestring' is not defined
------------------------------------------------------------
python receive.py 
Traceback (most recent call last):
  File "receive.py", line 5, in <module>
    host='localhost'))
  File "/home/hawk/g/sqlalchemy/lib/python3.3/site-packages/pika/connection.py", line 361, in __init__
    if host and self._validate_host(host):
  File "/home/hawk/g/sqlalchemy/lib/python3.3/site-packages/pika/connection.py", line 207, in _validate_host
    if not isinstance(host, basestring):
NameError: global name 'basestring' is not defined

这是什么情况?

python rabbitmq

草莓亮晶晶 10 years, 2 months ago

if not isinstance(host, basestring):

NameError: global name 'basestring' is not defined

说明basestring 不存在, 你需要import 进来或者定义这个变量
如 a="test"
if not isinstance(a, str): #str 是类型的类型, 所以不用导入, 如果不是就需要导入这个类或者方法
print "不是字符串类型"
else:
print "这个是字符串类型"

joehee answered 10 years, 2 months ago

Your Answer