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

TypeError: bytes required, not 'str', when feed includes url authentication #276

Closed
samuelclay opened this issue Apr 29, 2021 · 4 comments
Closed

Comments

@samuelclay
Copy link

Here's a simple testcase for the feed url https://username:password@example.com/feed/:

>>> import feedparser
>>> fp = feedparser.parse("https://username:password@example.com/feed/")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/feedparser/api.py", line 214, in parse
    data = _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
  File "/usr/local/lib/python3.9/site-packages/feedparser/api.py", line 114, in _open_resource
    return http.get(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers, result)
  File "/usr/local/lib/python3.9/site-packages/feedparser/http.py", line 148, in get
    auth = base64.standard_b64encode(f'{url_pieces.username}:{url_pieces.password}').strip()
  File "/usr/local/lib/python3.9/base64.py", line 95, in standard_b64encode
    return b64encode(s)
  File "/usr/local/lib/python3.9/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'
>>> feedparser.__version__
'6.0.2'

I figured basic http url authentication is supported, but that may not be the case?

@samuelclay
Copy link
Author

Found support in the documentation: https://feedparser.readthedocs.io/en/latest/http-authentication.html

@tms1987
Copy link

tms1987 commented May 22, 2021

@samuelclay How did you resolve this issue?
The documentation you linked at gives you two possiblities. Either in the way you described it in your first post which is not working or by using urllib2.
I have the same issue, but the urllib2 examples doesn't work for me as I am using Python 3 and have only urllib3 available.

@auouymous
Copy link
Contributor

PR #234 would fix it.

kurtmckee added a commit that referenced this issue Jun 14, 2021
@kurtmckee
Copy link
Owner

Samuel, thanks for reporting this. This is fixed in feedparser 6.0.5 thanks to @auouymous' PR.

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

No branches or pull requests

4 participants