Python Sketchfab API Example not working


(Poiu 1 2000) #1

Hi there,

I am trying to get an automated model upload via my own python tool (with python 3.6.4.).
I used the example from the data api python examples.

FYI: I have a basic account and tested the upload from blender via the exporter, which worked.

I added my API token and provided a zip file to the upload method.

I had to fix the code to work with python 3.
I added the () to the print statements and removed the u prefix.
old: print u'An error occured: {}'.format(e)
new: print('An error occured: {}'.format(e))

line 105 gave me a hard time and confused me a lot.
I always got the debug error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I think its because the response is not parsable as JSON, since it has html content.
I changed it from:
old: print('Upload failed with error: {}'.format(r.json()))
new: print('Upload failed with error: {}'.format(r.reason))
which then gave me at least the message:
Upload failed with error: Request Entity Too Large

But now I am stuck.
What’s the issue? The Zip file is only 7 MB.
What could be wrong?

Here is the full code:
(I removed all unneeded functions, comments and links (since this is my first post)


# -*- coding: utf-8 -*-

# Sample script for uploading to Sketchfab
# using the V3 API and the requests library
import json
import os

from time import sleep

import requests

SKETCHFAB_DOMAIN = 'sketchfab[dot]com'
SKETCHFAB_API_URL = 'https[semicolon]//api.{}/v3'.format(SKETCHFAB_DOMAIN)

YOUR_API_TOKEN = ' - my token (removed for this post)- '

def _get_request_payload(data={}, files={}, json_payload=False):
    """Helper method that returns the authentication token and proper content
    type depending on whether or not we use JSON payload."""
    headers = {'Authorization': 'Token {}'.format(YOUR_API_TOKEN)}

    if json_payload:
        headers.update({'Content-Type': 'application/json'})
        data = json.dumps(data)

    return {'data': data, 'files': files, 'headers': headers}

def upload(model_file):
    """POST a model to sketchfab.
    This endpoint only accepts formData as we upload a file.
    Parameter: model_file - relative path string to the zip file to upload
    model_endpoint = os.path.join(SKETCHFAB_API_URL, 'models')

    # Optional parameters
    name = 'test'
    description = 'test'
    #password = 'my-password'  # requires a pro account
    #private = 1  # requires a pro account
    tags = ['test']  # Array of tags
    #categories = ['gaming']  # Array of categories slugs
    #license = 'CC Attribution'  # License label
    isPublished = False, # Model will be on draft instead of published
    isInspectable = True, # Allow 2D view in model inspector

    data = {
        'name': name,
        'description': description,
        'tags': tags,
        'isPublished': isPublished,
        'isInspectable': isInspectable

    f = open(model_file, 'rb')

    files = {'modelFile': f}

    print ('Uploading ...')

        r =
            model_endpoint, **_get_request_payload(
                data, files=files))
    except requests.exceptions.RequestException as e:
        print ('An error occured: {}'.format(e))

    if r.status_code !=['created']:
        print('Upload failed with error: {}'.format(r.reason))

    model_url = r.headers['Location']
    print ('Upload successful. Your model is being processed.')
    print ('Once the processing is done, the model will be available at: {}'.format(model_url))

    return model_url

if __name__ == '__main__':
    modelFile = os.path.abspath('./data/')
    model_url = upload(modelFile)

    if model_url:
        print('Model URL: ' + model_url)


Thanks for the report. We’re looking into it!

(Poiu 1 2000) #3

any news?


Sorry, I didn’t get any information yet. I’ll ping our developers again.

(Ratdevil) #5

I’m trying also a personal Uploader.
Exactly the same issue for me on Python 2.7 with the code given here:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The first character given to JSON.loads seems to be inappropriate.

I found these interesting sources on the Web to help but I’m not strong enough to resolve it:

I tried this :

Model = "models/14.35-U04.igs"  # path to your model
model_file = unicode(Model, "utf-8")
print type(model_file)

without success



@tribble42 any idea?

(Uiuclibrary) #7

Bumping – I’m having the same issue.

(Uiuclibrary) #8

The problem for me was on Windows os.path.join() uses \ instead of /… Changing

model_endpoint = os.path.join(SKETCHFAB_API_URL, 'models')


model_endpoint = SKETCHFAB_API_URL+'/models'

worked for me.