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

Unexpected exception ('ascii' codec can't decode byte 0xae in position 621: ordinal not in range(128)) occurred fetching URL #1009

Closed
bcoles opened this issue Sep 9, 2020 · 3 comments
Labels

Comments

@bcoles
Copy link
Contributor

bcoles commented Sep 9, 2020

2020-09-09 14:42:57,715 [ERROR] Unexpected exception ('ascii' codec can't decode byte 0xae in position 621: ordinal not in range(128)) occurred fetching URL: http://<redacted>
2020-09-09 14:42:57,716 [ERROR] Traceback (most recent call last):
  File "/spiderfoot/sflib.py", line 2647, in fetchUrl
    result['content'] = res.content.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 621: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/spiderfoot/sflib.py", line 2649, in fetchUrl
    result['content'] = res.content.decode("ascii")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xae in position 621: ordinal not in range(128)
@leotrubach
Copy link
Contributor

leotrubach commented Sep 9, 2020

Maybe just

 except UnicodeDecodeError:
    pass

or

for encoding in ("utf-8", "ascii"):
    try:
        result["content"] = res.content.decode(encoding)
    except UnicodeDecodeError:
        pass
    else:
        break
else:
    result["content"] = res.content

@bcoles
Copy link
Contributor Author

bcoles commented Sep 11, 2020

The latter would probably be best.

This issue is left over from when SpiderFoot was written in Python2. Consumers of fetchUrl() expect res['content'] to be str(); however, in some instances it must be bytes(). It would be better to have the code fail in the module than fail in the library.

@smicallef
Copy link
Owner

I've pushed the fix provided but let's leave this bug open a little while longer until more testing has been done.

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

No branches or pull requests

3 participants