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

meet unicode encode error while audit the baseline #211

Closed
saturbo opened this issue Jul 25, 2019 · 6 comments
Closed

meet unicode encode error while audit the baseline #211

saturbo opened this issue Jul 25, 2019 · 6 comments
Assignees
Labels
good first issue The issue can be tackled by someone who has little to no knowledge about the project.

Comments

@saturbo
Copy link

saturbo commented Jul 25, 2019

Hi , guys , I met the unicode encode error when I was trying to audit the baseline. The detail as below:
Filename: src/main/java/com/XX/account/microservice/common/AccountConstants.java
Secret Type: Secret Keyword

Traceback (most recent call last):
File "/bin/detect-secrets", line 11, in
sys.exit(main())
File "/usr/lib/python2.7/site-packages/detect_secrets/main.py", line 64, in main
audit.audit_baseline(args.filename[0])
File "/usr/lib/python2.7/site-packages/detect_secrets/core/audit.py", line 83, in audit_baseline
original_baseline['plugins_used'],
File "/usr/lib/python2.7/site-packages/detect_secrets/core/audit.py", line 479, in _print_context
force=force,
File "/usr/lib/python2.7/site-packages/detect_secrets/core/audit.py", line 586, in _get_secret_with_context
snippet.highlight_line(raw_secret_value)
File "/usr/lib/python2.7/site-packages/detect_secrets/core/code_snippet.py", line 97, in highlight_line
self.apply_highlight(self.target_line[index_of_payload:end_of_payload]),
File "/usr/lib/python2.7/site-packages/detect_secrets/core/code_snippet.py", line 114, in apply_highlight
AnsiColor.RED_BACKGROUND,
File "/usr/lib/python2.7/site-packages/detect_secrets/core/color.py", line 17, in colorize
AnsiColor.RESET.value,
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Seeking help with this error.

@KevinHock KevinHock added bug good first issue The issue can be tackled by someone who has little to no knowledge about the project. labels Jul 25, 2019
@KevinHock
Copy link
Collaborator

KevinHock commented Jul 25, 2019

I’m currently on my phone, but a fix like #143 might work here, can you add that import at the top and see if it works for you @saturbo? 👍

e.g.
vim /usr/lib/python2.7/site-packages/detect_secrets/core/color.py
and then add

from __future__ import unicode_literals

to the top.

@KevinHock
Copy link
Collaborator

KevinHock commented Jul 25, 2019

I’ll be sure to grep for .format( later and make sure this line is added everywhere, thanks for making this! 🙏

@KevinHock KevinHock self-assigned this Jul 25, 2019
KevinHock added a commit that referenced this issue Jul 25, 2019
@saturbo
Copy link
Author

saturbo commented Jul 26, 2019

@KevinHock Thx. I add the code "from future import unicode_literals" to both main.py and color.py files and still not working.Below is the error message when audit the same file.For your reference.

Traceback (most recent call last):
File "/usr/bin/detect-secrets", line 11, in
sys.exit(main())
File "/usr/lib/python2.7/site-packages/detect_secrets/main.py", line 64, in main
audit.audit_baseline(args.filename[0])
File "/usr/lib/python2.7/site-packages/detect_secrets/core/audit.py", line 83, in audit_baseline
original_baseline['plugins_used'],
File "/usr/lib/python2.7/site-packages/detect_secrets/core/audit.py", line 481, in _print_context
print(secret_with_context)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 55-56: ordinal not in range(128)

@saturbo
Copy link
Author

saturbo commented Jul 26, 2019

@KevinHock I add below code in main.py by using utf-8 as default and it works fine with me now. But I just don't know running on UTF-8 for scan functionality will cross any issues . So far so good.

reload(sys)
sys.setdefaultencoding('utf-8')

@OiCMudkips
Copy link
Contributor

So I added an .encode('utf-8') to https://github.com/Yelp/detect-secrets/blob/master/detect_secrets/core/code_snippet.py#L113 and it fixed things locally, but I don't know if this will work in Python 3. Probably needs more testing.

killuazhu pushed a commit to IBM/detect-secrets that referenced this issue May 28, 2020
* Attempts to fix db2 detector

Installing from this branch and testing...

* debugging

* don't catch exception to see what it is

* Print username password

* Back to try except

* print conn string

* Fix single quote issue

* Test case

* Remove print statements

* Test case for double quotes

* code comment
killuazhu pushed a commit to IBM/detect-secrets that referenced this issue Jul 9, 2020
* Attempts to fix db2 detector

Installing from this branch and testing...

* debugging

* don't catch exception to see what it is

* Print username password

* Back to try except

* print conn string

* Fix single quote issue

* Test case

* Remove print statements

* Test case for double quotes

* code comment
@domanchi
Copy link
Contributor

Uncertain the action item to be taken here. Closing as fixed given the comment thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue The issue can be tackled by someone who has little to no knowledge about the project.
Projects
None yet
Development

No branches or pull requests

4 participants