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

[py3.6] TypeError: write() argument must be str, not bytes #5888

Closed
rplevka opened this issue Mar 28, 2018 · 7 comments
Closed

[py3.6] TypeError: write() argument must be str, not bytes #5888

rplevka opened this issue Mar 28, 2018 · 7 comments
Assignees
Labels
High Priority Get this done or merged soon

Comments

@rplevka
Copy link
Member

rplevka commented Mar 28, 2018

TypeError: write() argument must be str, not bytes

tests.foreman.api.test_repository/RepositoryTestCase/test_positive_access_protected_repository

@rplevka rplevka added High Priority Get this done or merged soon 6.2 TestFailure Issues and PRs related to a test failing in automation labels Mar 28, 2018
@rplevka rplevka self-assigned this Mar 28, 2018
@ldjebran
Copy link
Contributor

@rplevka The returned certificate from nailgun is byte in py3, so perhaps we have to update the nailgun download_debug_certificate to always return str

@rplevka
Copy link
Member Author

rplevka commented Mar 28, 2018

@ldjebran yeah, thanks for looking into this. yeah, this was just a placeholder issue, so i guess let's open up a nailgun one and keep it referenced

@jhutar
Copy link
Member

jhutar commented Mar 29, 2018

Created PR SatelliteQE/nailgun#485 with this change. I was unable to run the test because mine Sat is hand-installed so requests.exceptions.SSLError: HTTPSConnectionPool(host='sat630.example.com', port=443): Max retries exceeded with url: /pulp/repos/fksCpkEtnjvN/Library/custom/bQASRMxJp/jlbvdiCh/repodata/repomd.xml (Caused by SSLError(SSLError(336445449, '[SSL] PEM lib (_ssl.c:3405)'),)). I assume that is because of mine config.

@ldjebran
Copy link
Contributor

@jhutar no the problem was about the saved saved value that was not correctly returned as we should use decode('utf-8')

Think it seems to be more complicated to resolve that on nailgun perhaps fix the test to decode that returned value will be the simplest way to resolve this issue.

...
        with self.assertRaises(SSLError):
            client.get(repo_data_file_url, verify=False)
        # get the organization debug certificate
        cert_content = self.org.download_debug_certificate().decode('utf-8')
        # save the organization debug certificate to file
        cert_file_path = '{0}/{1}.pem'.format(
            tempfile.gettempdir(), self.org.label)
        with open(cert_file_path, 'w') as cert_file:
            cert_file.write(cert_content)
        # access repository data with organization debug certificate
        response = client.get(
            repo_data_file_url, cert=cert_file_path, verify=False)
...

This should work in python 2 and python 3

@lpramuk
Copy link
Contributor

lpramuk commented Mar 29, 2018

+1 couple of similar issues were solved by adding .decode('utf-8')

@jhutar
Copy link
Member

jhutar commented Mar 29, 2018

Cool. It works with the fix you both proposed in the Nailgun PR:

$ py.test tests/foreman/api/test_repository.py::RepositoryTestCase::test_positive_access_protected_repository
============================= test session starts ==============================
platform linux -- Python 3.6.4, pytest-3.4.0, py-1.5.3, pluggy-0.6.0
shared_function enabled - OFF - scope:  - storage: file
rootdir: /home/pok/Checkouts/robottelo, inifile:
plugins: services-1.2.1, mock-1.6.3
collected 1 item
2018-03-30 00:12:46 - conftest - DEBUG - Collected 1 test cases


tests/foreman/api/test_repository.py .                                   [100%]

============================== 0 tests deselected ==============================
========================== 1 passed in 47.34 seconds ===========================

@jhutar
Copy link
Member

jhutar commented Apr 3, 2018

SatelliteQE/nailgun#485 merged, so we are good here.

@jhutar jhutar closed this as completed Apr 3, 2018
@rochacbruno rochacbruno removed the TestFailure Issues and PRs related to a test failing in automation label Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority Get this done or merged soon
Projects
None yet
Development

No branches or pull requests

5 participants