Upload API error

i’ve been trying to use roboflow’s api to upload a lot to images and their annotation and i walked through the provided colab notebook to use it

this is the error

{'error': {'message': 'Unsupported get request. Dataset with ID `XXX` does not exist or cannot be loaded due to missing permissions.', 'type': 'GraphMethodException', 'hint': 'You can see your available datasets by issuing a GET request to /datasets'}}
KeyError                                  Traceback (most recent call last)
<ipython-input-10-a855405627e4> in <module>()
---> 40       img_id = r.json()['id']
     42       annotation_filename = os.path.splitext(filename)[0]+'.xml'

KeyError: 'id'

and I’ve used this section

import requests
import base64
import io
from PIL import Image
import os
for filename in os.listdir("."):
    if filename.endswith(".jpg") or filename.endswith(".png"):

      # Load Image with PIL
      image = Image.open(filename).convert("RGB")

      # Convert to JPEG Buffer
      buffered = io.BytesIO()
      image.save(buffered, quality=90, format="JPEG")

      # Base 64 Encode
      img_str = base64.b64encode(buffered.getvalue())
      img_str = img_str.decode("ascii")

      # Construct the URL
      upload_url = "".join([
          "?api_key=" + MY_KEY,

      # POST to the API
      r = requests.post(upload_url, data=img_str, headers={
          "Content-Type": "application/x-www-form-urlencoded"

      # Output result

      img_id = r.json()['id']

      annotation_filename = os.path.splitext(filename)[0]+'.xml'

      # Read Annotation as String
      annotation_str = open(annotation_filename, "r").read()

      # Construct the URL
      upload_url = "".join([
          "https://api.roboflow.com/dataset/XXX/annotate/" + img_id,
          "?api_key=" + MY_KEY,
          "&name=", annotation_filename

      # POST to the API
      r = requests.post(upload_url, data=annotation_str, headers={
          "Content-Type": "text/plain"

      # Output result

Hello @Ruba0 - thank you for the detailed code and error. In order to upload an image to Roboflow via the upload API you need to specify the dataset name where you have XXX and be sure to include you API key in the variable “MY_KEY”, which you may already have done.

Alternatively, you might prefer to use our PIP package to upload your data - where we have wrapped some of these API nuances

thank you @Jacobsolawetz for the reply!
I tried uploading images and it works but how can I upload their annotations?

error                                     Traceback (most recent call last)
<ipython-input-26-e41f30109986> in <module>()
      1 project.upload("1007_test.jpg")
----> 2 project.upload("1007_test.xml")

2 frames
/usr/local/lib/python3.7/dist-packages/roboflow/core/project.py in __image_upload(self, image_path, hosted_image, split)
    110             # Convert to PIL Image
    111             img = cv2.imread(image_path)
--> 112             image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    113             pilImage = Image.fromarray(image)

error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

That looks like an error reading your image, can you display it successfully with your current installation of cv2?

Hi I have used the roboflow package and tried to upload image by using following code snippet

rf = Roboflow(api_key=API_KEY)
project = rf.workspace("caitesting").project("pdf_images")

Here i have a workspace called “caitesting” and project called “pdf_images”.but when i executed above command it will give error as following.

Hi Nipun, this would be the correct code:

rf = Roboflow(api_key=API_KEY)
workspace = rf.workspace()
project = workspace.project("pdf_images")
1 Like

Cool Thanks,I could be able to manage above problem by using same code with different image dimensions.is there any restriction on image dimensions ?

There’s no requirement to pass the image dimensions with the inference query.

There is a 10MB payload limit. However, you can pass a larger image if you pass it via URL from where you may already have uploaded it image={url}

1 Like

Thanks for your quick reply.but when i tried to upload following image from my dataset.It won’t upload properly to the Roboflow project.Then i resized following image into (640,640) and then it worked

Roboflow Package has been used for uploading.so can you take a look at this problem? because in my end Roboflow api will work if images are resized to smaller size.