jonthornton / MTAPI

JSON proxy server for the MTA's realtime New York City subway feed
283 stars 83 forks source link

WIP Make compatible with Python 3 #11

Closed abachant closed 5 years ago

abachant commented 6 years ago

I was looking to make this compatible with Python 2 and 3, but I am getting stuck with Google protobuf:

Traceback (most recent call last):
  File "/home/garrett/anaconda3/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 1083, in MergeFromString
    if self._InternalParse(serialized, 0, length) != length:
  File "/home/garrett/anaconda3/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 1105, in InternalParse
    (tag_bytes, new_pos) = local_ReadTag(buffer, pos)
  File "/home/garrett/anaconda3/lib/python3.6/site-packages/google/protobuf/internal/decoder.py", line 181, in ReadTag
    while six.indexbytes(buffer, pos) & 0x80:
TypeError: unsupported operand type(s) for &: 'str' and 'int'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 13, in <module>
    from mtapi import Mtapi
  File "/home/garrett/Desktop/Programs/MTAPI/mtapi/__init__.py", line 2, in <module>
    from .mtapi import Mtapi
  File "/home/garrett/Desktop/Programs/MTAPI/mtapi/mtapi.py", line 16, in <module>
    from mtaproto.feedresponse import FeedResponse, Trip, TripStop, TZ
  File "/home/garrett/Desktop/Programs/MTAPI/mtaproto/feedresponse.py", line 1, in <module>
    from mtaproto import nyct_subway_pb2
  File "/home/garrett/Desktop/Programs/MTAPI/mtaproto/nyct_subway_pb2.py", line 12, in <module>
    from . import gtfs_realtime_pb2
  File "/home/garrett/Desktop/Programs/MTAPI/mtaproto/gtfs_realtime_pb2.py", line 1149, in <module>
    DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), '\n\033com.google.transit.realtime')
  File "/home/garrett/anaconda3/lib/python3.6/site-packages/google/protobuf/descriptor.py", line 874, in _ParseOptions
    message.ParseFromString(string)
  File "/home/garrett/anaconda3/lib/python3.6/site-packages/google/protobuf/message.py", line 185, in ParseFromString
    self.MergeFromString(serialized)
  File "/home/garrett/anaconda3/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 1089, in MergeFromString
    raise message_mod.DecodeError('Truncated message.')
google.protobuf.message.DecodeError: Truncated message.

Any advice/input would be appreciated.

jonthornton commented 5 years ago

I had to recompile the protobufs. Fixed here https://github.com/jonthornton/MTAPI/commit/7711077203fcc2725635bc3fabf4235c2188b633