agoragames / haigha

AMQP Python client
BSD 3-Clause "New" or "Revised" License
161 stars 41 forks source link

SyntaxError on fresh install with python 7 #100

Open johns10 opened 6 years ago

johns10 commented 6 years ago

After installing haigha with pip I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\johns10\AppData\Local\Programs\Python\Python37\lib\site-packages\haigha\connection.py", line 7, in <module>
    from haigha.channel import Channel
  File "C:\Users\johns10\AppData\Local\Programs\Python\Python37\lib\site-packages\haigha\channel.py", line 10, in <module>
    from haigha.frames.frame import Frame
  File "C:\Users\johns10\AppData\Local\Programs\Python\Python37\lib\site-packages\haigha\frames\frame.py", line 74
    raise Frame.FormatError, str(e), sys.exc_info()[-1]
                           ^
SyntaxError: invalid syntax

I tested this on my local machine (win 10/python 3.7), and on a python:3.7-alpine docker build:


webserver_1  |   File "code/webserver.py", line 9, in <module>
webserver_1  |     from haigha.connection import Connection
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/haigha/connection.py", line 7, in <module>
webserver_1  |     from haigha.channel import Channel
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/haigha/channel.py", line 10, in <module>
webserver_1  |     from haigha.frames.frame import Frame
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/haigha/frames/frame.py", line 74
webserver_1  |     raise Frame.FormatError, str(e), sys.exc_info()[-1]
webserver_1  |                            ^
webserver_1  | SyntaxError: invalid syntax```
johns10 commented 6 years ago

The offending line is:

from haigha.connection import Connection

Changed lines 72-76 in frame.py:

            except Reader.ReaderError as e:
                # Some other format error
                raise (Frame.FormatError, str(e), sys.exc_info()[-1])
            except struct.error as e:
                raise (Frame.FormatError, str(e), sys.exc_info()[-1])

Commented line 280 and 283 in writer.py (I think these types are depreciated in python 3)

Commented line 19 in connection.py (I think exceptions is rolled in to core)

After that the import statement worked - gonna go see if I can get the thing rolling. Sorry I'm not sharp enough to do a diff or anything like that for you guys.

johns10 commented 6 years ago

Also changed iteritems to items in writer.py (line 188) and channel.py (line 65).

johns10 commented 6 years ago

Changed line 144 to:

if isinstance(s, str):

in writer.py

johns10 commented 6 years ago

The next error was:


  File "code/webserver.py", line 21, in <module>
    connection = Connection(user='user',password='pass',vhost='/vhost', host='rabbitmq:5672', hearbeat=None, debug=True)
  File "/usr/local/lib/python3.7/site-packages/haigha/connection.py", line 107, in __init__
    {'LOGIN': self._user, 'PASSWORD': self._password})
  File "/usr/local/lib/python3.7/site-packages/haigha/writer.py", line 189, in write_table
    self._write_item(key, value)
  File "/usr/local/lib/python3.7/site-packages/haigha/writer.py", line 198, in _write_item
    self.write_shortstr(key)
  File "/usr/local/lib/python3.7/site-packages/haigha/writer.py", line 146, in write_shortstr
    self.write_octet(len(s))
  File "/usr/local/lib/python3.7/site-packages/haigha/writer.py", line 81, in write_octet
    self._output_buffer.append(pack(n))
TypeError: an integer is required
johns10 commented 6 years ago

I'm assuming this isn't fully converted to python 3?