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

urls.py crashes on Darwin under Python 3.5: An unknown error occurred: a bytes-like object is required, not 'str' #19265

Closed
arigesher opened this issue Dec 12, 2016 · 0 comments · Fixed by #19852
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. net_tools Net-tools category python3

Comments

@arigesher
Copy link

arigesher commented Dec 12, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

lib/ansible/module_utils/urls.py

ANSIBLE VERSION
ansible 2.2.0.0
  config file = /Users/regs/work/pantsibot/ansible.cfg
  configured module search path = ['./library']
(work-python3) eve|15:01|~/work/pantsibot% 

CONFIGURATION
[defaults]
roles_path = ./roles:../roles
inventory = ./config/inventory
library = ./library
host_key_checking = False
OS / ENVIRONMENT

MacOS Sierra 10.12.1
Darwin eve 16.1.0 Darwin Kernel Version 16.1.0: Thu Oct 13 21:26:57 PDT 2016; root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64

Python 3.5 in a virtualenv

SUMMARY

urls.py uses an outdated set of assumptions about os.write()

STEPS TO REPRODUCE

Attempt to load any https URL via fetch_url()

Minimal playbook:

- name: fetch something via https
  hosts: localhost
  tasks:
    - get_url:
        url: https://hooks.slack.com/
        dest: /tmp/bugout.txt
EXPECTED RESULTS

Merrily loading the URL as requested

ACTUAL RESULTS
fatal: [localhost]: FAILED! => {
    "changed": false,
    "dest": "/tmp/bugout.txt",
    "failed": true,
    "invocation": {
        "module_args": {
            "backup": false,
            "checksum": "",
            "content": null,
            "delimiter": null,
            "dest": "/tmp/bugout.txt",
            "directory_mode": null,
            "follow": false,
            "force": false,
            "force_basic_auth": false,
            "group": null,
            "headers": null,
            "http_agent": "ansible-httpget",
            "mode": null,
            "owner": null,
            "regexp": null,
            "remote_src": null,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "sha256sum": "",
            "src": null,
            "timeout": 10,
            "tmp_dest": "",
            "unsafe_writes": null,
            "url": "https://hooks.slack.com/",
            "url_password": null,
            "url_username": null,
            "use_proxy": true,
            "validate_certs": true
        },
        "module_name": "get_url"
    },
    "msg": "Request failed",
    "response": "An unknown error occurred: a bytes-like object is required, not 'str'",
    "state": "absent",
    "status_code": -1,
    "url": "https://hooks.slack.com/"
}

Instrumenting the code to surface the traceback, got me this:

Traceback (most recent call last):
  File "/var/folders/x2/drqpb67n01n4225h701ht8l80000gn/T/ansible_r1m8tgtj/ansible_modlib.zip/ansible/module_utils/urls.py", line 971, in fetch_url
    follow_redirects=follow_redirects)
  File "/var/folders/x2/drqpb67n01n4225h701ht8l80000gn/T/ansible_r1m8tgtj/ansible_modlib.zip/ansible/module_utils/urls.py", line 886, in open_url
    r = urllib_request.urlopen(*urlopen_args)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 463, in open
    req = meth(req)
  File "/var/folders/x2/drqpb67n01n4225h701ht8l80000gn/T/ansible_r1m8tgtj/ansible_modlib.zip/ansible/module_utils/urls.py", line 654, in http_request
    tmp_ca_cert_path, paths_checked = self.get_ca_certs()
  File "/var/folders/x2/drqpb67n01n4225h701ht8l80000gn/T/ansible_r1m8tgtj/ansible_modlib.zip/ansible/module_utils/urls.py", line 597, in get_ca_certs
    os.write(tmp_fd, DUMMY_CA_CERT)
TypeError: a bytes-like object is required, not 'str'
arigesher added a commit to arigesher/ansible that referenced this issue Dec 12, 2016
@ansibot ansibot added affects_2.2 This issue/PR affects Ansible v2.2 bug_report python3 labels Dec 13, 2016
abadger added a commit to abadger/ansible that referenced this issue Jan 4, 2017
os.write() needs bytes objects on python3 while python2 can work with
either a byte or unicode string.  Mark the DUMMY_CA_CERT string as
a byte string so it will work.

Fixes ansible#19265
Fixes ansible#19266
abadger added a commit that referenced this issue Jan 4, 2017
os.write() needs bytes objects on python3 while python2 can work with
either a byte or unicode string.  Mark the DUMMY_CA_CERT string as
a byte string so it will work.

Fixes #19265
Fixes #19266
abadger added a commit that referenced this issue Jan 4, 2017
os.write() needs bytes objects on python3 while python2 can work with
either a byte or unicode string.  Mark the DUMMY_CA_CERT string as
a byte string so it will work.

Fixes #19265
Fixes #19266
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@dagwieers dagwieers added the net_tools Net-tools category label Mar 3, 2019
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. net_tools Net-tools category python3
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants