SSL error when uploading version through API

Hi,

we would like to upload movies or images through the API directly to Shotgun. We have no problem doing any operations but there is an issue with the upload, giving this error :

Traceback (most recent call last):
File “\tools\shotgun\sgprod.py”, line 104, in
session.upload(“Version”, version[‘id’], img_file, “sg_uploaded_movie”)
File “\tools\python\site-packages\shotgun_api3\shotgun.py”, line 2343, in upload
tag_list, is_thumbnail)
File “\tools\python\site-packages\shotgun_api3\shotgun.py”, line 2379, in _upload_to_storage
self._upload_file_to_storage(path, upload_info[“upload_url”])
File “\hydro\tools\python\site-packages\shotgun_api3\shotgun.py”, line 3794, in _upload_file_to_storage
self._upload_data_to_storage(fd, content_type, file_size, storage_url)
File “\hydro\tools\python\site-packages\shotgun_api3\shotgun.py”, line 3886, in _upload_data_to_storage
result = opener.open(request)
File “C:\Python27\lib\urllib2.py”, line 429, in open
response = self._open(req, data)
File “C:\Python27\lib\urllib2.py”, line 447, in _open
‘_open’, req)
File “C:\Python27\lib\urllib2.py”, line 407, in _call_chain
result = func(*args)
File “C:\Python27\lib\urllib2.py”, line 1241, in https_open
context=self._context)
File “C:\Python27\lib\urllib2.py”, line 1198, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>

We did read through some older messages we could find online, some solutions from Shotgun website are not accessible anymore, we tried the other suggestion we could find or think of such as :

  • using Python 2.7.16
  • updated to latest shotgun_api3 package
  • added the three following lines in our code (which gave an other error written below)

import ssl
import functools
partialcreateHttps = functools.partial(ssl._create_default_https_context, cafile=‘C:\tmp\cert.pem’, capath=‘C:\tmp\certs’)
ssl._create_default_https_context = partialcreateHttps

Traceback (most recent call last):
File “\tools\shotgun\sgprod.py”, line 104, in
session.upload(“Version”, version[‘id’], img_file, “sg_uploaded_movie”)
File “\tools\python\site-packages\shotgun_api3\shotgun.py”, line 2343, in upload
tag_list, is_thumbnail)
File “\tools\python\site-packages\shotgun_api3\shotgun.py”, line 2371, in _upload_to_storage
upload_info = self._get_attachment_upload_info(is_thumbnail, filename, is_multipart_upload)
File “\tools\python\site-packages\shotgun_api3\shotgun.py”, line 2521, in _get_attachment_upload_info
upload_info = self._send_form(url, params)
File “\tools\python\site-packages\shotgun_api3\shotgun.py”, line 3979, in _send_form
resp = opener.open(url, params)
File “C:\Python27\lib\urllib2.py”, line 429, in open
response = self._open(req, data)
File “C:\Python27\lib\urllib2.py”, line 447, in _open
‘_open’, req)
File “C:\Python27\lib\urllib2.py”, line 407, in _call_chain
result = func(*args)
File “C:\Python27\lib\urllib2.py”, line 1241, in https_open
context=self._context)
File “C:\Python27\lib\urllib2.py”, line 1167, in do_open
h = http_class(host, timeout=req.timeout, **http_conn_args)
File “C:\Python27\lib\httplib.py”, line 1247, in init
context = ssl._create_default_https_context()
File “C:\Python27\lib\ssl.py”, line 440, in create_default_context
context.load_verify_locations(cafile, capath, cadata)
IOError: [Errno 2] No such file or directory

Any suggestion?

Thanks
Chris

2 Likes

Additionally, the python code used to upload the file :

version = get_version(session, 8792)
img_file = ‘C:\tmp\hdrex.jpg’
session.upload(“Version”, version[‘id’], img_file, “sg_uploaded_movie”)

Where “session” is the shotgun_api3.Shotgun object.

Thanks!

1 Like

Hi Chris

Welcome to the forums!

The certificate doc you were looking for was moved, you can find it here now.

Hopefully, this will help.
Thanks
Phil

2 Likes

Hi Philip,

thanks! That helped a lot!

For anyone that may have the issue in the future, I ended up creating the Shogun object while adding the certificate :

this_path = os.path.abspath(os.path.dirname(shotgun_api3.file))
ca_certs_path = os.path.join(this_path, “lib/httplib2/python2/cacerts.txt”)

session = shotgun_api3.Shotgun(
https://ourcompany.shotgunstudio.com”,
script_name=“ourscript”,
ca_certs=ca_certs_path,
api_key=“ourAPIkey”
)

not quite sure why it’s not already like this by default though

3 Likes