Skip to content

Error messages are not converted from bytes to str in Python 3 #616

Closed

Description

@Lucidiot

Description of the problem, including code/CLI snippet

When trying to create webhooks on a repository with invalid URLs (like 127.x.x.x), GitLab returns HTTP 422 with a JSON body : {"error":"Invalid url given"}. Under Python 3, the GitlabCreateError does not convert from bytes to str :

from gitlab import Gitlab
from gitlab.exceptions import GitlabCreateError

gl = Gitlab('https://gitlab.com', oauth_token="<TOKEN>")
project = gl.projects.get('<PROJECT>')

try:
    project.webhooks.create({'url': 'http://127.0.0.1/'})
except GitlabCreateError as e:
    print(str(e))

Expected Behavior

Under both Python 2 and 3, the above snippet should print

422: {"error": "Invalid url given"}

Actual Behavior

Under Python 2, it works as expected. Under Python 3 only, this prints

422: b'{"error": "Invalid url given"}'

Specifications

  • python-gitlab version: 1.5.1
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): GitLab.com (11.4.0-rc7-ee)

Activity

  1. self-assigned this
    on Nov 24, 2018
  2. added a commit that references this issue on Nov 24, 2018
    1fb1296
  3. locked as resolved and limited conversation to collaborators on Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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