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

ensure correct value type in data field of Request object in Python 2/3 #2806

Merged
merged 2 commits into from Mar 12, 2019

Conversation

boegel
Copy link
Member

@boegel boegel commented Mar 9, 2019

Without this fix, the added test fails as below when using Python 3.

This is relevant for features like --upload-test-report.

ERROR: test_restclient (__main__.GithubTest)
Test use of RestClient.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Volumes/work/easybuild-framework/test/framework/github.py", line 575, in test_restclient
    status, body = client.user.emails.post(body='test@example.com')
  File "/Volumes/work/easybuild-framework/easybuild/base/rest.py", line 136, in post
    return self.request(self.POST, url, json.dumps(body), headers, content_type='application/json')
  File "/Volumes/work/easybuild-framework/easybuild/base/rest.py", line 167, in request
    conn = self.get_connection(method, url, body, headers)
  File "/Volumes/work/easybuild-framework/easybuild/base/rest.py", line 201, in get_connection
    connection = self.opener.open(request)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 523, in open
    req = meth(req)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1247, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

@boegel boegel added bug fix python3 Python 3 compatibility labels Mar 9, 2019
@boegel boegel added this to the 4.0 milestone Mar 9, 2019
@boegel boegel requested a review from wpoely86 March 9, 2019 22:00

status, body = client.repos['hpcugent']['testrepository'].contents.a_directory['a_file.txt'].get()
self.assertEqual(status, 200)
# dGhpcyBpcyBhIGxpbmUgb2YgdGV4dAo= == 'this is a line of text' in base64 encoding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you encode this on the fly instead of this comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stole this from the vsc-base checks, I have to admit I don't know why it was done like this.

Will try and encode on the fly...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in e0e1e16

@wpoely86 wpoely86 merged commit 3ecbc63 into easybuilders:4.x Mar 12, 2019
@boegel boegel deleted the fix_rest_post_bytes_value branch March 12, 2019 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix python3 Python 3 compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants