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

Extras Image Attachment fails due to incorrect content type #520

Open
egreenspan2 opened this issue Dec 9, 2022 · 0 comments
Open

Extras Image Attachment fails due to incorrect content type #520

egreenspan2 opened this issue Dec 9, 2022 · 0 comments
Labels
status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@egreenspan2
Copy link

Attempting to attach an image to dcim.device using this sample code:

  with open("file_file.jpg", "rb") as file_handle:

        image_data = file_handle.read()

    base_encoded = base64.b64encode(image_data).decode("utf8")

    image_data = dict(
        content_type="dcim.device",
        object_id=1234,
        name="Test image",
        image=base_encoded,
        image_height=1234,
        image_width=1234,
    )
    try:
        nb_api.extras.image_attachments.create(image_data)
    except pynetbox.RequestError:
        log.exception(f"Failed to attach image")

Catching RequestError

   File "blah/venv/lib/python3.10/site-packages/pynetbox/core/query.py", line 287, in _make_call
       raise RequestError(req)
  pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'image': ['The submitted data was not a file. Check the encoding type on the form.']}`

I believe the issue is that the Content-Type should be set to "multipart/form-data" for this to work.

Any suggestions are appreciated, is there a way to change content-type here? Or am I missing something simple?

@abhi1693 abhi1693 added type: bug A confirmed report of unexpected behavior in the application status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants