Skip to content

cr doesn't work on Python 3.13? #19

Closed
@ehmatthes

Description

@ehmatthes

I was trying out CodeRed for the first time, and getting inconsistent behavior between several projects I was deploying. I finally narrowed it down to cr working in 3.12 environments, and failing in 3.13 environments.

This is on macOS, using zsh, but I think this is an issue relating to the use of urlopen() in cr/api.py. In 3.13, urlopen() no longer accepts a cafile argument. I got it to work by modifying request_json() in api.py, but it's just a demo; I'm not sure the best place to put that change, or if I used the best approach.

Reproduction

Here's a 3.12 session that makes a cr check call against a fake project, returning the expected Error: No Webapp matches the given query. A 3.13 session with the same call generates an API error.

~/test_code/cr_cli_test$ export CR_TOKEN=<redacted>
~/test_code/cr_cli_test$ python -V
Python 3.12.8
~/test_code/cr_cli_test$ uv venv .venv && source .venv/bin/activate      
Using Python 3.12.8 interpreter at: /Users/eric/.pyenv/versions/3.12.8/bin/python3.12
...
(cr_cli_test) ~/test_code/cr_cli_test$ uv pip install cr
...
 + cr==1.7
...
(cr_cli_test) ~/test_code/cr_cli_test$ cr check fake-project
Error: No Webapp matches the given query.
(cr_cli_test) ~/test_code/cr_cli_test$ deactivate
~/test_code/cr_cli_test$ rm -rf .venv
~/test_code/cr_cli_test$ pyenv local 3.13.1
~/test_code/cr_cli_test$ uv venv .venv && source .venv/bin/activate
Using Python 3.13.1 interpreter at: /Users/eric/.pyenv/versions/3.13.1/bin/python3.13
...
(cr_cli_test) ~/test_code/cr_cli_test$ uv pip install cr
...
 + cr==1.7
...
(cr_cli_test) ~/test_code/cr_cli_test$ cr check fake-project
Error: Error contacting CodeRed API. Please try again shortly.
(cr_cli_test) ~/test_code/cr_cli_test$ cr check fake-project --debug
INFO     Read config files: []                                                                                                                                                                config.py:36
DEBUG    Config `token`: `<redacted>`                                                                                                                                   config.py:67
ERROR    Fatal: Error contacting CodeRed API. Please try again shortly.                                                                                                                         cli.py:680
         ╭──────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────────────────────╮           
         │ /Users/eric/test_code/cr_cli_test/.venv/lib/python3.13/site-packages/cr/api.py:457 in coderedapi                                                                                   │           
         │                                                                                                                                                                                    │           
         │   454 │   """
         │   455 │   endpoint = endpoint.lstrip("/")                                                                                                                                          │           
         │   456 │   try:                                                                                                                                                                     │           
         │ ❱ 457 │   │   code, d = request_json(                                                                                                                                              │           
         │   458 │   │   │   f"https://app.codered.cloud/{endpoint}",                                                                                                                         │           
         │   459 │   │   │   method=method,                                                                                                                                                   │           
         │   460 │   │   │   headers={                                                                                                                                                        │           
         │                                                                                                                                                                                    │           
         │ /Users/eric/test_code/cr_cli_test/.venv/lib/python3.13/site-packages/cr/api.py:429 in request_json                                                                                 │           
         │                                                                                                                                                                                    │           
         │   426 │                                                                                                                                                                            │           
         │   427 │   # Open the request and read the response.                                                                                                                                │           
         │   428 │   try:                                                                                                                                                                     │           
         │ ❱ 429 │   │   r = urlopen(req, timeout=timeout, cafile=certifi.where())                                                                                                            │           
         │   430 │   │   d = _response_to_json(r)                                                                                                                                             │           
         │   431 │   │   code = r.code                                                                                                                                                        │           
         │   432 │   │   LOGGER.info("%s %s %d", method, url, code)                                                                                                                           │           
         ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯           
         TypeError: urlopen() got an unexpected keyword argument 'cafile'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions