Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error on Python 3 in NMEA Stream Reader #87

Closed
sterwen opened this issue Apr 17, 2019 · 5 comments
Closed

Runtime error on Python 3 in NMEA Stream Reader #87

sterwen opened this issue Apr 17, 2019 · 5 comments

Comments

@sterwen
Copy link

sterwen commented Apr 17, 2019

<class 'bytes'> <class 'str'>
Traceback (most recent call last):
File "GPS_nmea.py", line 112, in
main()
File "GPS_nmea.py", line 106, in main
pos=nmeatty.getNMEAPosition()
File "GPS_nmea.py", line 69, in getNMEAPosition
for msg in self._reader.next():
File "/usr/local/lib/python3.4/dist-packages/pynmea2/stream.py", line 49, in next
lines = (self.buffer + data).split('\n')
TypeError: Can't convert 'bytes' object to str implicitly

@Knio
Copy link
Owner

Knio commented May 12, 2019

GPS_nmea.py looks like your own code here, and not pynmea.
The error seems to be that you are not decoding your input to ASCII before passing it to pynmea.

@Knio Knio closed this as completed May 12, 2019
@sterwen
Copy link
Author

sterwen commented May 13, 2019 via email

@sterwen
Copy link
Author

sterwen commented May 13, 2019

Hello,

The bug still exist line 48 in the current version
lines = (self.buffer + data).split('\n')
This will raise an error because self.buffer is type while data is type <>
Here how I made it compatible with both versions:
if type(data) == str : line = data else: line = data.decode('ascii')
I have also removed the buffer because it is never used.

@xOneca
Copy link
Contributor

xOneca commented May 13, 2019

Actually, self.buffer is used. Specifically if data contains more than just one message, but last one is not yet complete.

@xOneca
Copy link
Contributor

xOneca commented Dec 1, 2019

I think self.buffer should be initialized to b'', instead of '', because it seems that NMEAStreamReader.stream.readline() returns type bytes, not str.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants