tristantao / py-bing-search

Python Bing Search API
MIT License
46 stars 37 forks source link

Handling of unicode characters #9

Closed MaZZly closed 8 years ago

MaZZly commented 8 years ago

Doesn't seem to hande Unicode characters too well..

# Fails
bing.search_all(u'óla', limit=50)
>>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 0: ordinal not in range(128)

# Works
bing.search_all(u'óla'.encode('utf-8'), limit=50)
>>> [results]

Would it be good to add the encoding built-in to the code?

My suggestion would be to add to py_bing_search.py:37 a line:

query = query.encode('utf-8')

However I suck when it comes to unicode and the like so this might bring errors for other strings?

evanmiltenburg commented 8 years ago

I made a Python 3 fork that takes care of this bug (because Python 3 is awesome like that): https://github.com/evanmiltenburg/py-bing-search

result = bing.search("olá", limit=50, format='json') result ([LIST OF RESULTS], "https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Query='ol%C3%A1'&$skip=50&$top=50")

The relevant commit is this one. There's also another python 3 fork (see the pull request) in this repo. Note that I am using my repo just to fool around with the interface, so later commits will be ugly hacks for my use case.

tristantao commented 8 years ago

Yea, it seems to work in the newest version, closing now.