get_build_artifact() tries to parse results as JSON, rendering non-Json artifacts impossible to download

Bug #2018576 reported by Frans
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Jenkins
New
Undecided
Unassigned

Bug Description

Trying to download (potentially binary) artifacts via

```
jenkins_client.get_build_artifact("some_job", 42, "some-file.zip")
```

Results in errors like

```
DEBUG 2023-05-05 09:40:44 urllib3.connectionpool: https://base.url.com:443 "GET /job/some_job/42/artifact/some-file.zip HTTP/1.1" 200 17376
DEBUG 2023-05-05 09:40:44 charset_normalizer: Encoding detection: ascii is most likely the one.
Traceback (most recent call last):
  File "../site-packages/jenkins/__init__.py", line 731, in get_build_artifact
    return json.loads(response)
           ^^^^^^^^^^^^^^^^^^^^
  File "../json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
```

This seems to happen because `jenkins/__init__.py` implements `get_build_artifact()` expecting JSON result:
```
response = self.jenkins_open(requests.Request(
        'GET', self._build_url(BUILD_ARTIFACT, locals())))

if response:
    return json.loads(response)
else:
    raise JenkinsException('job[%s] number[%s] does not exist' % (name, number))
```

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.