patrickbr / db-api-to-gtfs

Small hack to convert data from the Deutsche Bahn API into a valid GTFS feed
https://gtfs.de
GNU General Public License v2.0
34 stars 5 forks source link

Unicode issue outputting German special characters #3

Closed highsource closed 8 years ago

highsource commented 8 years ago

I was getting the following error:

Traceback (most recent call last):
  File "C:\Projects\workspaces\dbopendata\db-api-to-gtfs4\db_to_gtfs.py", line 492, in <module>
    main(options=arguments)
  File "C:\Projects\workspaces\dbopendata\db-api-to-gtfs4\db_to_gtfs.py", line 472, in main
    converter.get_all_trips_for_stop(converter.stops[sid])
  File "C:\Projects\workspaces\dbopendata\db-api-to-gtfs4\db_to_gtfs.py", line 83, in get_all_trips_for_stop
    print '@ #%d (%s) on %s %s, unique trips collected: %d, unprocessed stations left: %d' % (stop['stop_id'], stop['stop_name'], stop['last_date'].strftime('%Y-%m-%d'), str(stop['last_check_h']) + ':' + str(stop['last_check_m']), len(self.trips), self.unproced_counter)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 21: ordinal not in range(128)

Fixed via stop['stop_name'].encode('utf-8').strip().

patrickbr commented 8 years ago

Confirmed, only seems to occur on windows machines.

highsource commented 8 years ago

I also got it on AWS EC2 instance running Debian 8.