microsoft / studentambassadors

This repository is for Microsoft Learn Student Ambassadors.
MIT License
130 stars 47 forks source link

Error Uploading Image to Custom Studio Prediction API using Python Request Library #176

Open bumie-e opened 1 year ago

bumie-e commented 1 year ago

Describe the bug

I tried uploading an image using the Custom Vision prediction API enpoint for sending images, but I got back this error. {'code': 'BadRequestImageFormat', 'message': 'Bad Request Image Format, Uri: ef9a72a7a60541f0bd7fbefc32f5e7b8'} I used Python requests library, and set the files to the image bytes data.

To Reproduce

Steps to reproduce the behavior:

  1. Go to Custom Vision Studio, click on Publish, then Performance.
  2. Click on Prediction URL and select the credentials for 'If you have an image file'
  3. In your .py file, set the headers = { 'Prediction-Key': key, 'Content-Type': 'application/octet-stream'}
  4. Create the request image_request = requests.post(constructed_url, headers=headers, files=bytes_data)
  5. Running that line gives the error

Expected behavior

It supposed to return a JSON response like this {'id':.., 'project': ...', 'iteration':.., 'created': '2023-03-13T21:50:19.587Z', 'predictions': [{'probability': 0.9999995...

Screenshots

Screenshot 2023-03-14 195014

Desktop (please complete the following information):

Additional context

I am trying to use REST API to upload an image to Azure Custom Service Prediction API with Python Requests library. The current documentation only supports the Python SDK.


🎓 Add a tag to this issue for your current education role: student, Student Ambassador or educator.

Student Ambassador


github-actions[bot] commented 1 year ago

Thank you for submitting this issue! The team will review your issue, tag with the appropriate tags, and comment with any additional questions on information needed. :sparkles: