-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Fixed issue with printing unicode #126
Conversation
To fix error with printing unicode
Fix problem with printing unicode
Hi Darrel, Can you post some examples of songs that were giving you errors before this change? Thanks, |
"'Till I Collapse" by Eminem was the only one I encountered before modifying the code. I was trying to download all of Eminem's songs. I think there were a lot because I had it print a message in the console every time it would happen at first, but I couldn't see exactly which songs were doing it. |
I can't recreate this issue with the latest version of the package (1.8.2). Can you test your search with the latest version of the package? Or provide example code that produces the error? John |
|
Hi @DarrelDonald, sorry for the delay. Are you still running into this issue? What version of Python and OS are you using? |
I haven't used it since then. I was using Python 3.5 and my operating system was Windows 10. |
@johnwmillr, this happened to me too recently. Try this: song = genius.search_song('60 days sober and cool', artist='Noah Cyrus')
song.to_text('song.txt') The problem is with the |
@allerter, does the snippet you shared produce an error for you? When running in my environment, the song saves without issue. |
@johnwmillr, it does. I guess it might have to do with my environment. But either way, the problem in this issue is probably an actual problem. It's because the Windows console uses a different charset but Python 3 deals in Unicode. So when trying to print a string that has Unicode characters, it results in an error in Python 3.5 and lower. This was solved in 3.6 since Python bypasses console I/O to support Unicode. If someone with 3.5 and lower wanted to be able to print Unicode they would have to do this (from a solution on SO):
|
Thanks for the explanation, @allerter. Do you know of a package-wide approach that would address the <= 3.5 issue that would be more robust than adding |
@johnwmillr, unfortunately, I don't know of a package-wide way to achieve this. We could probably set the
def print_unicode(s):
print(s.encode('utf-8').decode(sys.stdout.encoding, errors='replace')) The good thing about this function is that if the user's console can print Unicode characters, it will print everything, and when it can't, it will display the text with the unicode character like |
added encoding='utf8' when saving text files
updated utils
moved Artist and Song to types added TokenRequiredError updated docs,
added public_api to methods (incomplete)
added the public_api attr to Genius, removed pytest from dependencies
update TokenRequiredError, update overlapping methods
This reverts commit 3386282644198706639e858098af18b560976ccd.
- added "discussions" public API endpoint, - updated docs
reconfigured Genius.lyrics() to: * fetch the page through the Sender * extract the lyrics not only more concisely, but also without changing the original format of the lyrics (adding newlines) * reconfigured Sender to: * allow making requests to Genius at https://genius.com * remove SLEEP_TIME to allow users to supply their own rate limiting (by default 0.2) instead of enforcing it * move the authorization header to the authorization_header attribute instead of re-creating it for every API call
* to check lyrics_state along with the title * reconfigured search_* that return an object: * to check lyrics_state to avoid getting empty lyrics * moved setting excluded_terms to __init__ * moved _clean_str to utils and renamed to clean_str * added tests for genius.tag * reordered some of the imports and the functions alphabetically
- fix genius.tag() example
This comment has been minimized.
This comment has been minimized.
* added text_format parameter to account() * added try/finally close to test_manage_annotation to try to delete created annotation if an exception occurs
- genius.tag(): replaced unicodedata.normalize with only replacing \xa0
😅 I think I forgot to squash the merge. As |
Another solution would be to use the |
I resolved the conflicts but there was a green commit merge and since I wasn't sure if it would update the package or the PR, I didn't submit it. |
The PR looks good! Thank you @DarrelDonald and @allerter for your work on this. Merging now. |
* Update to origin (#8) * added auth * added voting methods for annotations * renamed client_access_token to access_token * added documentation for authorization, renamed all instances of client_access_token to access_token * fixed instance parse_redirected_url didn't work with 'token' flow * added OAuth2 documentation, modified OAuth2 to make it user-friendlier * removed Authenticating yourself from snippets, added missing commas * Revert "removed Authenticating yourself from snippets," This reverts commit d2e99bb. * added missing comma * added more missing commas * added missing word in sippets * changed get_user_auth_url to auth.url property, changed 'all' scope type to tuple, fixed combining scopes (changed ',' to ' ') * changed calling get_user_auth_url to url * fixed client_only_app not in OAuth2 attributes * fixed parse_redirected_url * set None in POST body params when optional annotation parameteres aren't supplied * revert to current _make_request * fixed typo * added some docs, fixed new methods' payload * fixed response for 204 response, added tests * fixed added test bugs * fixed update_annotation and added its test, added docs for contributing * added example redirect uri to snippets * commit changes * add text_format to API annotation methods * fixed prompt_user bug * fix flake8 error * fixed bugs, added auth tests * fix test_url error * fix wrong function name * removed test_url Co-authored-by: John W. Miller <johnwmillr@users.noreply.github.com> * - added encoding using utf-8 when saving files - removed binary encoding - genius.tag(): replaced unicodedata.normalize with only replacing \xa0 - fixed IndentationError - __main__: made import relative * fix flake8 error Co-authored-by: John W. Miller <johnwmillr@users.noreply.github.com>
Whenever there were unicode characters that needed to be printed, an error would be produced. I encoded the print statements and it resolved the issue.