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

Use keyword 'should contain' , raise error:a bytes-like object is required, not 'str' #3254

Closed
ding-jing opened this issue Aug 1, 2019 · 2 comments

Comments

@ding-jing
Copy link

ding-jing commented Aug 1, 2019

It works in python2

Should Contain Any ${res.content} cdmtest

but in python3:

FAIL : TypeError: a bytes-like object is required, not 'str'

@ding-jing
Copy link
Author

the Requests library has changed.
r.content is 'bytes' instead of 'str', if i change it to r.text , the bug can be avoided.

@pekkaklarck
Copy link
Member

This isn't really a bug. It's just that in Python 3 text and bytes are not compatible with each others at all. In Python 2 you can mix and match to some extend, but if bytes contain non-ASCII characters you get an exception. With request, you should use response.text if the content is text both in Python 2 and 3.

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

2 participants