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

HTTP Error 422 when trying to upload a pdf file to a asset via python requests #16183

Open
DasMoorhuhn opened this issue Feb 5, 2025 · 1 comment

Comments

@DasMoorhuhn
Copy link

DasMoorhuhn commented Feb 5, 2025

Hello,

When I try to upload a pdf file via python requests to a asset, it failes with error 422. I followed the guide on https://snipe-it.readme.io/reference/uploading-files and with curl it works, but when I use python requests, it won't work. Am I doing anything wrong here?

headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Accept": "application/json",
    "Content-Type": "application/json",
}

file_name = "abc_123.pdf"

file = {
    "file[]": open(file=file_name, mode="rb")
}

requesturl = f"https://my-snipe-it.local/api/v1/hardware/1234/files"

response = requests.post(
    requesturl,
    files=file,
    headers=headers,
)

Response:
HTTP 422: {"status": "error", "messages": "Invalid JSON", "payload":null}

What I have tried so far:

  • "file": open(file=file_name, mode="rb")
  • "file": open(file=file_name, mode="rb").read()
  • "file": f"{open(file=file_name, mode="rb").read()}"
  • "file[]": open(file=file_name, mode="rb").read()
  • "file[]": f"{open(file=file_name, mode="rb").read()}"
  • Using the payload parameter for requests.post()

Some help would be really nice :)

Greetings, DasMoorhuhn

Copy link

welcome bot commented Feb 5, 2025

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant