shotgunsoftware / python-api Goto Github PK
View Code? Open in Web Editor NEWA Python-based API for accessing Flow Production Tracking.
Home Page: https://developer.shotgridsoftware.com/python-api
License: Other
A Python-based API for accessing Flow Production Tracking.
Home Page: https://developer.shotgridsoftware.com/python-api
License: Other
Hey,
Just hit this myself when trying to create a Shotgun PublishedFile and include a thumbnail image with it.
It appears that the sg-media-usor-01
got a bit overloaded with traffic and S3 told us (python api) to slow down.
Because I was naively using the create
method to also handle my "image" field, I now get an error after the entity has been created, however I don't know what id the created entity has.
My workaround has been to copy out the upload logic from the create
method and wrap it in a retry loop with some sleeping, but it is not ideal.
Is this something that I could propose and get merged in if I wrote a proper implementation for it?
Thanks
-Alex
IronPython 2.7.4 has an issue on value.decode from unicode in many unit tests:
File "C:\dev\wspy\sandbox_shared\src\shotgun\python_api3\tests\test_api.py", line 24, in setUp
self.sg.update('Note', self.note['id'], {'content':u'La Pe\xf1a'})
.....
File "C:\dev\wspy\sandbox_shared\src\shotgun\python_api3\shotgun_api3\shotgun.py", line 1823, in _outbound_visitor
return value.decode("utf-8")
UnicodeDecodeError: ('unknown', u'\xf1', 4, 5, '')
see here for list of unit tests:
https://dl.dropboxusercontent.com/u/4995745/201411/shotgun-IronPython-api-unittests_in_test_api_20141118.html
If you give Shotgun.followers() an id that doesn't exist it causes the server to have a 500 error. This happens in Shotgun v6.0.3 (build 04eae45) with python-api master (e92bece).
In [3]: sg.followers({'type': 'Shot', 'id': 1167})
---------------------------------------------------------------------------
ProtocolError Traceback (most recent call last)
<ipython-input-3-b5726fc21ace> in <module>()
----> 1 sg.followers({'type': 'Shot', 'id': 1167})
/home/ashworth/.virtualenvs/tmp-3463e352d8613412/lib/python2.7/site-packages/shotgun_api3/shotgun.py in followers(self, entity)
1054 )
1055
-> 1056 return self._call_rpc('followers', params)
1057
1058 def schema_entity_read(self, project_entity=None):
/home/ashworth/.virtualenvs/tmp-3463e352d8613412/lib/python2.7/site-packages/shotgun_api3/shotgun.py in _call_rpc(self, method, params, include_auth_params, first)
1683 LOG.debug("Completed rpc call to %s" % (method))
1684 try:
-> 1685 self._parse_http_status(http_status)
1686 except ProtocolError, e:
1687 e.headers = resp_headers
/home/ashworth/.virtualenvs/tmp-3463e352d8613412/lib/python2.7/site-packages/shotgun_api3/shotgun.py in _parse_http_status(self, status)
1853 error_code,
1854 errmsg,
-> 1855 headers)
1856
1857 return
ProtocolError: <ProtocolError for brandon.shotgunstudio.com: 500 Internal Server Error>
Tested on python api v3.2.4, but haven't seen anything in 3.2.6 that would fix this.
When running the update function on a datetime field the return value is a string, rather than the datetime.datetime expected.
This string is also not compatible with plugging back in to further updates.
Example below;
import datetime
from tank_vendor.shotgun_api3.lib.sgtimezone import UTC
from tank.util import shotgun
utc_now = datetime.datetime.now(UTC())
sg = shotgun.create_sg_connection()
# update date field with utc date, returns as string
sg.update('PublishedFile', 433118, {'sg_accessed_at': utc_now})
>>> {'sg_accessed_at': '2020-11-27 09:52:29 UTC', 'type': 'PublishedFile', 'id': 433118}
# for comparison, find_one returns as datetime with tzinfo
sg.find_one('PublishedFile', [['id', 'is', 433118]], ['sg_accessed_at'])
>>> {'sg_accessed_at': datetime.datetime(2020, 11, 27, 9, 52, 29, tzinfo=<tank_vendor.shotgun_api3.lib.sgtimezone.LocalTimezone object at 0x7fdff227b8d0>), 'type': 'PublishedFile', 'id': 433118}
# plugging that string back into an update throws an error
sg.update('PublishedFile', 433118, {'sg_accessed_at': '2020-11-27 09:52:29 UTC'})
>>> Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 1435, in update
record = self._call_rpc("update", params)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3314, in _call_rpc
self._response_errors(response)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3619, in _response_errors
raise Fault(sg_response.get("message", "Unknown Error"))
Fault: Invalid date time format: 2020-11-27 09:52:29 UTC. Correct format is 2011-01-21T13:26:09Z (UTC) or 2011-01-21T13:26:09-07:00 (UTC Offset)
# note, the recommended format also throws an error
sg.update('PublishedFile', 433118, {'sg_accessed_at': '2020-11-27T09:52:29Z (UTC)'})
>>> Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 1435, in update
record = self._call_rpc("update", params)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3314, in _call_rpc
self._response_errors(response)
File "/TCP/home/spencere/toolkit_dev/install/core/python/tank_vendor/shotgun_api3/shotgun.py", line 3619, in _response_errors
raise Fault(sg_response.get("message", "Unknown Error"))
Fault: Invalid date time format: 2020-11-27T09:52:29Z (UTC). Correct format is 2011-01-21T13:26:09Z (UTC) or 2011-01-21T13:26:09-07:00 (UTC Offset)
Hey, would it be possible to get this package into pypi?
We currently download all our other python dependencies from pypi, but with this package, we have had to fork it and upload it to our own internal pypi server. Thanks
29th April 2017 - CY2018 Draft published with significant upgrades to gcc and glibc. This also comes with notice of our intention to move to Python 3 for CY2019 in advance of Python 2 support ending in 2020. We are currently soliciting feedback on this Draft so please either send to [email protected] or share on vfx-platform-discuss. We expect to publish CY2018 Final around SIGGRAPH in July.
When using an 'any' filter_operator and mocking, I get an :
Traceback (most recent call last):
File "/home/marie/rdoenv/python_libs/pure/rodeo/tests/integration_tests/test_ilm_ocio_profile.py", line 121, in test_shotFilter
for config in configs.shotConfigMap.iterkeys():
File "/home/marie/rdoenv/python_libs/pure/rodeo/color/ilm_ocio_profile.py", line 122, in shotConfigMap
for sgShot in self.sgShots:
File "/home/marie/rdoenv/python_libs/pure/rodeo/color/ilm_ocio_profile.py", line 63, in sgShots
self._sgShots = self.sg.find('Shot', queryFilters, ['code', 'sg_cdl_path', 'sg_client_name'])
File "/home/marie/rdoenv/python_libs/pure/shotgun_api3/lib/mockgun.py", line 339, in find
elif f[1] == "in" and not isinstance(f[2], list):
KeyError: 1
The same code is working when not mocking.
Code sample :
queryFilters = [['project.Project.code', 'is', self.projectCode],
['sg_status_list', 'not_in', ['bid', 'awd', 'omt', 'void', 'hdn']]
]
if self.shotFilters:
# Keep only the shots that are corresponding to the filters
shotQueryFilters = []
for shotFilter in self.shotFilters:
shotQueryFilters.append(['code', 'starts_with', shotFilter])
queryFilters.append({
"filter_operator": "any",
"filters": shotQueryFilters
})
self._sgShots = self.sg.find('Shot', queryFilters, ['code', 'sg_cdl_path', 'sg_client_name'])
Thanks !
I am new to this api and am wondering if there is a way to unlink an asset that was added to the Related Assets tab on a Shot. I tried
from shotgun_api3.shotgun import Shotgun
Shotgun.update("Shot", 2531, {"assets":[{"type":"Asset", "id":3425}]},
multi_entity_update_modes={"assets":"remove"})
but this didn't seem to work. Any suggestions? Thank you :)
A facility like oAuth is a necessity for a completely secure ecosystem. For those serving their Action Menu Items on a Web server, oAuth would offer a way to seamlessly authenticate the session with shotgun.
Currently, after clicking an Action Menu Item, users are prompted to login separately on the Web server. There are two ways to approach this:
Option 1 Requires users to login with a separate username and password from their shotgun account. It uses a static API key for subsequent API requests.
Option 2 Requires the storage of the user's plaintext shotgun credentials in a cookie or on the server. It uses these credentials to authenticate the subsequent API requests
There needs to be a way to checkout a temporary session token for API requests. This way users can leverage the shotgun API with their own identity and with the security of a single login facility with the guaranteed security already built into shotgun's authentication.
What's the recommended way to handle connection issues, i.e. slow or broken connections?
Is it safe just to use signals to cancel out of stalled/slow calls to the API?
pip install git+git://github.com/shotgunsoftware/[email protected]
should be replaced by
pip install git+https://github.com/shotgunsoftware/[email protected]
python-api/shotgun_api3/shotgun.py
Lines 590 to 594 in 41c5369
Previously, e.g. in v3.0.22, instantiating a Shotgun
object did NOT contact the server. Determining the value of records_per_page
should be deferred when connect=False
.
The API doesn't seem to be compatible with Python 3
Using the following variables:
project_name = 'SuperStickman'
episode_name = 'Stic-101'
I want to extract ALL the Project, Episode and Shot fields together.
I tried these two different ways, but they don't display Project, Episode and Shot fields.
sg_shots = sg.find("Shot", [['project.Project.name', 'is', project_name],['episode.Episode.name', 'is', episode_name]], ['code', 'sg_sequence.Sequence.sg_status_list'])
sg_shots = sg.find("Shot", [['project.Project.name', 'is', project_name]], ['code', 'sg_sequence.Sequence.sg_status_list'])
How do I return a query result that returns ALL the Project, Episode and Shot fields together?
Thank you in advance.
I've been looking to find an answer to this for quite a while but couldn't find anything in the docs…
I try to retrieve a version together with its notes, but I need to have more of the notes than just the standard fields that are retrieved.
Here's the relevant part:
def getVersion(id):
sg = Shotgun("supplied","supplied","supplied")
response = sg.find_one("Version", [["id", "is", int(id)]], ['id', 'notes', 'notes.Note.content'])
return response
I thought notes.Note.content
would be the right way to do it but since it is a collection, it does not seem to work. The response does not give me the notes content fields but just this:
{
"notes": [
{
"type": "Note",
"id": 25797,
"name": "Example User on 008_010_v103 and 008_010 - this is a test"
}
],
"type": "Version",
"id": 4068
}
Is there any way to get specified fields of the notes list or do I need to perform another query to get these?
The following code:
shotgun.find(
"Version",
order=[{"field_name": "playlists.PlaylistVersionConnection.sg_sort_order", "direction": "asc"}],
)
Results in the following error:
shotgun_api3.shotgun.Fault: API read() CRUD ERROR #10: Read failed for entity type [Version]
This is probably an issue on the server side rather than the python api client, but I would expect to be able to sort by the Playlists > Sort Order
field though the API in the same way you can through the UI.
Looks like the idna encoding needs to be converted again to utf-8 for IronPython:
h = Http(".cache")
thumb_resp, content = h.request(version_with_thumbnail.get('image'), "GET")
test_humanuser_upload_thumbnail_for_version
Error
Traceback (most recent call last):
File "C:\dev\wspy\sandbox_shared\src\shotgun\python_api3\tests\test_api.py", line 1551, in test_humanuser_upload_thumbnail_for_version
thumb_resp, content = h.request(version_with_thumbnail.get('image'), "GET")
LookupError: unknown encoding: idna
When I share a playlist (example below) via shotugun API, associated note submissions hang on submitting...
def sharePlaylist(sg, playlistID, clientID):
filters = [ ['playlist', 'is', {'type': 'Playlist', 'id': playlistID}] ]
fields = ['playlist', 'user']
share = sg.find_one('PlaylistShare', filters, fields)
if not share:
data = {'playlist': {'type': 'Playlist', 'id': playlistID}, 'user': {'id': clientID, 'type': 'ClientUser'}}
fields = ['playlist', 'user']
return sg.create('PlaylistShare', data, fields)
else:
return share
@pboucher explained this is not supported in the API. Can we get support for this? Perhaps I'm simply missing something in my code above?
Hello,
Is there a way to retrieve the items of a List type Field with the API?
Thanks
I generally base exceptions on StandardError because it's usually bad policy to catch Exception because it's too broad. PyCharm complains about it so I know it's not just my own issue.
Would it harm downstream exc handlers to base off of StandardError or something even lower in the exc mro?
Any handlers which are already catching Exception won't be affected. StopIteration and Warming excs don't seem to be necessary for the ShotgunError exc hier.
Hi,
noticed with this stack trace :
File "../python-2.7/shotgun_api3/sg_26.py", line 5, in <module>
from .lib.httplib2 import Http, ProxyInfo, socks, SSLHandshakeError
File "../python-2.7/shotgun_api3/lib/httplib2/__init__.py", line 59, in <module>
from httplib2 import socks
File "../python-2.7/httplib2/__init__.py", line 915, in <module>
class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
AttributeError: 'module' object has no attribute 'HTTPSConnection'
As you can see :
you have integrated httplib2
into shotgun_api3.lib sub-package.
you correctly use it with it : from .lib.httplib2 import Http, ProxyInfo, socks, SSLHandshakeError
but then you should also have adapted the import at line 59 of shotgun_api3/lib/httplib2/__init__.py
to from shotgun_api3.lib.httplib2 import socks
or the better from . import socks
.
cause like that you actually use a part of the integrated httplib2 you made a copy and a part of the normal httplib2 which can comes in any environment where we need to use shotgun_api3.. which may or may not be compatible..
I don't know if there are no other such import to adapt in the different things you have integrated into/under shotgun_api3/lib/*
On Fedora Silverblue 37 I tried:
sudo rpm-ostree install python3-pip
but it failed.
Here's a workaround that works for Silverblue 37:
git clone https://github.com/shotgunsoftware/python-api.git sgpythonapi
cd sgpythonapi/
sudo python3 setup.py install
I'm able to create sg and do sg.find()/sg.find_one() after that.
As I'm in the midst of troubleshooting SSL error for select users, I saw there is update to httplib2
and decided to update shotgun_api3
.
While it can run fine when executing through a Python interpreter, my studio pipeline requires the tool to be compiled as a standalone exe for artists usage. Here's the error message when trying to run the EXE after upgrading from 3.3.0 to 3.3.2.
Currently my workaround is to pip install pyparsing==2.4.7
and modify both site-packages/shotgun_api3/lib/httplib2/python2/auth.py
and site-packages/shotgun_api3/lib/httplib2/python3/auth.py
# Existing code
# from ... import pyparsing as pp
# My fix after pip install pyparsing
import pyparsing as pp
After the changes above, I can build normally and run the EXE without issue.
My dev setup is the following:
I'm excluding the other libraries since they don't use pyparsing
P/S: This is more for other users, there is no need for me to modify the shotgun_api3
package for prior version from 3.3.0 and older when building an EXE using pyinstaller.
According to this migration support doc re: personal access tokens, for continued functionality of my company's scripts, we need to bind a Personal Access Token from our Autodesk ID to our ShotGrid account.
It's unclear, however, what combinations of credentials we should use with the Shotgun API for authentication going forward, after binding this PAT to our ShotGrid account. Additionally, I've yet to find an unambiguous way to prove that binding PATs to our shotgrid accounts is all we need to do for continued functionality.
After binding a PAT to my ShotGrid account, I wrote the script at the end of this issue (following the demo code in the video here) to test all possible combinations of credentials - only the following combinations worked:
server=PROXY, login=SG_USER, password=SG_PASS, tfa=SG_2FA
server=SG_SERVER, login=SG_USER, password=SG_PASS, tfa=SG_2FA
This indicates that only shotgrid credentials - and not those associated with my autodesk ID - work for authentication, even after PAT binding. It is implied in the documentation - though not made sufficiently explicit - that this is the intended behavior, and that by binding a PAT to our ShotGrid account all scripts should be able to work with no changes whatsoever. But, again - I've found no way to definitively prove this. If I'm wrong, several hundred of our employees may find themselves unable to continue with work after Friday.
If I'm right - if all we need to do is bind PATs to each of our employees ShotGrid accounts - there's the question of implementation. Do all of our employees need to manually generate PATs for each of their ShotGrid accounts, or is there some way to do this automatically for everyone in our domain?
Here's the script I used to check things:
from shotgun_api3.shotgun import Shotgun
import json
import itertools as it
params = json.load(open('params.json'))
servers = [
'PROXY',
'SG_SERVER'
]
logins = [
'AD_USER',
'AD_EMAIL',
'SG_USER',
]
passwords = [
'AD_PASS',
'SG_PASS',
]
twofa = [
'SG_2FA',
'AD_2FA'
]
if __name__ == "__main__":
import sys
filters = [['sg_status_list', 'is', 'act']]
fields = ['id']
tfa_cache = {
'SG_2FA': 'NUMS',
'AD_2FA': 'MORE_NUMS'
}
for server, login, password, tfa in it.product(servers, logins, passwords, twofa):
server_value = params[server].encode('utf-8')
login_value = params[login].encode('utf-8')
pw_value = params[password].encode('utf-8')
tfa_value = tfa_cache[tfa].encode('utf-8')
print("trying:")
print('server="{}", login="{}", password="{}", tfa="{}"'.format(server, login, password, tfa))
try:
sg = Shotgun(
server_value,
login=login_value,
password=pw_value,
auth_token=tfa_value
)
n_users = len(sg.find('HumanUser', filters, fields))
print('WORKED!')
except Exception as e:
print("FAILED... Error: {}".format(e))
I can't use the newer versions of shotgun.py because of the relative imports. I'm using python 2.4, which I know doesn't support them, but Shotgun is supposed to support that version. I don't think python gets to check the sys.version_info and then decide which import to try as the author intended (line 51ish); I seem to be crashing immediately because 2.4 considers it invalid syntax.
We just encounter the issue on Windows that Python 2.7 threw a TypeError on mimetypes initialization.
C:\Python27>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
C:\Python27>python -c "import mimetypes; mimetypes.init()"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\mimetypes.py", line 351, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 254, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: must be string without null bytes or None, not str
The suggested workaround is to catch the TypeError when the Shotgun API first uses mimetypes
import mimetypes # used for attachment upload
try:
mimetypes.add_type('video/webm','.webm') # try adding to test for unicode error
except (UnicodeDecodeError, TypeError):
# Ticket #25579 python bug on windows with unicode
# Ticket #23371 mimetypes initialization fails on Windows because of TypeError (http://bugs.python.org/issue23371)
# Use patched version of mimetypes
from .lib import mimetypes as mimetypes
See also: mimetypes initialization fails on Windows because of TypeError (http://bugs.python.org/issue23371)
Since Python 3 support was added, I can't build Pyinstaller executables with shotgun import in them. The build completes, but I get the following error:
File "dependecies\shotgun_api3\lib\six.py", line 82, in _import_module __import__(name) ImportError: No module named xmlrpclib
It was working with version <= 3.0.41
Hi,
Even though Python 3.7 is specified as a requirement, the install does not work with it:
> D:\python-api-3.2.3\python-api-3.2.3>python setup.py install --user
running install
running bdist_egg
running egg_info
creating shotgun_api3.egg-info
writing shotgun_api3.egg-info\PKG-INFO
writing dependency_links to shotgun_api3.egg-info\dependency_links.txt
writing top-level names to shotgun_api3.egg-info\top_level.txt
writing manifest file 'shotgun_api3.egg-info\SOURCES.txt'
reading manifest file 'shotgun_api3.egg-info\SOURCES.txt'
writing manifest file 'shotgun_api3.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\shotgun_api3
copying shotgun_api3\shotgun.py -> build\lib\shotgun_api3
copying shotgun_api3\__init__.py -> build\lib\shotgun_api3
creating build\lib\shotgun_api3\lib
copying shotgun_api3\lib\mimetypes.py -> build\lib\shotgun_api3\lib
copying shotgun_api3\lib\sgsix.py -> build\lib\shotgun_api3\lib
copying shotgun_api3\lib\sgtimezone.py -> build\lib\shotgun_api3\lib
copying shotgun_api3\lib\six.py -> build\lib\shotgun_api3\lib
copying shotgun_api3\lib\xmlrpclib.py -> build\lib\shotgun_api3\lib
copying shotgun_api3\lib\__init__.py -> build\lib\shotgun_api3\lib
creating build\lib\shotgun_api3\lib\httplib2
copying shotgun_api3\lib\httplib2\__init__.py -> build\lib\shotgun_api3\lib\httplib2
creating build\lib\shotgun_api3\lib\mockgun
copying shotgun_api3\lib\mockgun\errors.py -> build\lib\shotgun_api3\lib\mockgun
copying shotgun_api3\lib\mockgun\mockgun.py -> build\lib\shotgun_api3\lib\mockgun
copying shotgun_api3\lib\mockgun\schema.py -> build\lib\shotgun_api3\lib\mockgun
copying shotgun_api3\lib\mockgun\__init__.py -> build\lib\shotgun_api3\lib\mockgun
creating build\lib\shotgun_api3\lib\httplib2\python2
copying shotgun_api3\lib\httplib2\python2\certs.py -> build\lib\shotgun_api3\lib\httplib2\python2
copying shotgun_api3\lib\httplib2\python2\iri2uri.py -> build\lib\shotgun_api3\lib\httplib2\python2
copying shotgun_api3\lib\httplib2\python2\socks.py -> build\lib\shotgun_api3\lib\httplib2\python2
copying shotgun_api3\lib\httplib2\python2\__init__.py -> build\lib\shotgun_api3\lib\httplib2\python2
creating build\lib\shotgun_api3\lib\httplib2\python3
copying shotgun_api3\lib\httplib2\python3\certs.py -> build\lib\shotgun_api3\lib\httplib2\python3
copying shotgun_api3\lib\httplib2\python3\iri2uri.py -> build\lib\shotgun_api3\lib\httplib2\python3
copying shotgun_api3\lib\httplib2\python3\socks.py -> build\lib\shotgun_api3\lib\httplib2\python3
copying shotgun_api3\lib\httplib2\python3\__init__.py -> build\lib\shotgun_api3\lib\httplib2\python3
copying shotgun_api3\lib\httplib2\python2\cacerts.txt -> build\lib\shotgun_api3\lib\httplib2\python2
copying shotgun_api3\lib\httplib2\python3\cacerts.txt -> build\lib\shotgun_api3\lib\httplib2\python3
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\shotgun_api3
creating build\bdist.win-amd64\egg\shotgun_api3\lib
creating build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2
creating build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2
copying build\lib\shotgun_api3\lib\httplib2\python2\cacerts.txt -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2
copying build\lib\shotgun_api3\lib\httplib2\python2\certs.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2
copying build\lib\shotgun_api3\lib\httplib2\python2\iri2uri.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2
copying build\lib\shotgun_api3\lib\httplib2\python2\socks.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2
copying build\lib\shotgun_api3\lib\httplib2\python2\__init__.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2
creating build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3
copying build\lib\shotgun_api3\lib\httplib2\python3\cacerts.txt -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3
copying build\lib\shotgun_api3\lib\httplib2\python3\certs.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3
copying build\lib\shotgun_api3\lib\httplib2\python3\iri2uri.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3
copying build\lib\shotgun_api3\lib\httplib2\python3\socks.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3
copying build\lib\shotgun_api3\lib\httplib2\python3\__init__.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3
copying build\lib\shotgun_api3\lib\httplib2\__init__.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2
copying build\lib\shotgun_api3\lib\mimetypes.py -> build\bdist.win-amd64\egg\shotgun_api3\lib
creating build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun
copying build\lib\shotgun_api3\lib\mockgun\errors.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun
copying build\lib\shotgun_api3\lib\mockgun\mockgun.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun
copying build\lib\shotgun_api3\lib\mockgun\schema.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun
copying build\lib\shotgun_api3\lib\mockgun\__init__.py -> build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun
copying build\lib\shotgun_api3\lib\sgsix.py -> build\bdist.win-amd64\egg\shotgun_api3\lib
copying build\lib\shotgun_api3\lib\sgtimezone.py -> build\bdist.win-amd64\egg\shotgun_api3\lib
copying build\lib\shotgun_api3\lib\six.py -> build\bdist.win-amd64\egg\shotgun_api3\lib
copying build\lib\shotgun_api3\lib\xmlrpclib.py -> build\bdist.win-amd64\egg\shotgun_api3\lib
copying build\lib\shotgun_api3\lib\__init__.py -> build\bdist.win-amd64\egg\shotgun_api3\lib
copying build\lib\shotgun_api3\shotgun.py -> build\bdist.win-amd64\egg\shotgun_api3
copying build\lib\shotgun_api3\__init__.py -> build\bdist.win-amd64\egg\shotgun_api3
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2\certs.py to certs.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2\iri2uri.py to iri2uri.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2\socks.py to socks.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python2\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3\certs.py to certs.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3\iri2uri.py to iri2uri.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3\socks.py to socks.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\python3\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\httplib2\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\mimetypes.py to mimetypes.cpython-37.pyc
File "build\bdist.win-amd64\egg\shotgun_api3\lib\mimetypes.py", line 571
print USAGE
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(USAGE)?
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun\errors.py to errors.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun\mockgun.py to mockgun.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun\schema.py to schema.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\mockgun\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\sgsix.py to sgsix.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\sgtimezone.py to sgtimezone.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\six.py to six.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\xmlrpclib.py to xmlrpclib.cpython-37.pyc
File "build\bdist.win-amd64\egg\shotgun_api3\lib\xmlrpclib.py", line 191
MAXINT = 2L**31-1
^
SyntaxError: invalid syntax
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\lib\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\shotgun.py to shotgun.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\shotgun_api3\__init__.py to __init__.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying shotgun_api3.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying shotgun_api3.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying shotgun_api3.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying shotgun_api3.egg-info\not-zip-safe -> build\bdist.win-amd64\egg\EGG-INFO
copying shotgun_api3.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
creating dist
creating 'dist\shotgun_api3-3.2.3-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing shotgun_api3-3.2.3-py3.7.egg
creating c:\users\thomas\appdata\roaming\python\python37\site-packages\shotgun_api3-3.2.3-py3.7.egg
Extracting shotgun_api3-3.2.3-py3.7.egg to c:\users\thomas\appdata\roaming\python\python37\site-packages
File "c:\users\thomas\appdata\roaming\python\python37\site-packages\shotgun_api3-3.2.3-py3.7.egg\shotgun_api3\lib\mimetypes.py", line 571
print USAGE
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(USAGE)?
File "c:\users\thomas\appdata\roaming\python\python37\site-packages\shotgun_api3-3.2.3-py3.7.egg\shotgun_api3\lib\xmlrpclib.py", line 191
MAXINT = 2L**31-1
^
SyntaxError: invalid syntax
Adding shotgun-api3 3.2.3 to easy-install.pth file
Installed c:\users\thomas\appdata\roaming\python\python37\site-packages\shotgun_api3-3.2.3-py3.7.egg
Processing dependencies for shotgun-api3==3.2.3
Finished processing dependencies for shotgun-api3==3.2.3
Any plan to update the vendored modules/packages?
Cheers,
Thomas
We're trying to use pyinstaller for easy internal deployment of a single executable written in python.
Compiling works:
pyinstaller sgflop.py -F --upx-dir=/usr/bin/ --hidden-import=shotgun_api3 --hidden-import=ssl --hidden-import=httplib2 --hidden-import=_ssl --hidden-import=certifi --hidden-import=os
Execution fails with this error:
Traceback (most recent call last):
File "sgflop.py", line 25, in <module>
File "shotgun_api3/shotgun.py", line 439, in __init__
File "shotgun_api3/shotgun.py", line 458, in server_caps
File "shotgun_api3/shotgun.py", line 485, in info
File "shotgun_api3/shotgun.py", line 1640, in _call_rpc
File "shotgun_api3/shotgun.py", line 1761, in _make_call
File "shotgun_api3/shotgun.py", line 1779, in _http_request
File "shotgun_api3/lib/httplib2/__init__.py", line 1448, in request
File "shotgun_api3/lib/httplib2/__init__.py", line 1200, in _request
File "shotgun_api3/lib/httplib2/__init__.py", line 1135, in _conn_request
File "shotgun_api3/lib/httplib2/__init__.py", line 902, in connect
File "shotgun_api3/lib/httplib2/__init__.py", line 84, in _ssl_wrap_socket
File "ssl.py", line 381, in wrap_socket
File "ssl.py", line 141, in __init__
ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib
Failed to execute script sgflop
I found a solution in this thread. Now it works, but I believe this should be elegantly implemented in the httplib2 lib inside shotgun.
Is this something you would include if I file a pull request? Any suggestion how to wrap the certficate in the code?
P.S. Did I mention I would prefer to use a go package for shotgun
Hi all,
Wanted to raise this issue regarding shotgun_api3 and support for async workflows?
Happy to do the work and PR myself, but I'd like to get opinions on this first!
Thanks,
Josh
Hi! While profiling some of our internal code that we needed to speed up, I noticed that the Shotgun API seemed to have a bottleneck at the json decoding stage (in _json_loads_ascii
) I've been running my tests on Python 2.7 and I'm 98% sure we've got the C speedups for simplejson in place, so I don't think that's the issue.
For these preliminary benchmarks, I'm using cprofile to find the cumulative time of making an SG.find() call 10x, which returns the number of entities specified in the lefthand column. The difference is negligible at low numbers, but ujson seems to be exponentially faster at decoding when larger amounts of data are returned (times are in seconds):
entities | simplejson | ujson |
---|---|---|
1 | 0.003 | 0.000 |
10 | 0.013 | 0.000 |
100 | 0.105 | 0.001 |
1000 | 0.955 | 0.012 |
10000 | 7.791 | 0.108 |
I'm wondering if there's a known reason to not utilize a faster library for decoding json returned by the Shotgun API? I did notice that ujson doesn't appear to have the object_hook arg currently being used in _json_loads_ascii
; removing this wasn't having any negative impact in my tests, but I'd be interested in knowing when this object_hook is necessary (since we might consider moving our own fork to ujson.)
python-api/shotgun_api3/shotgun.py
Line 851 in b3034c1
As there is the rest api, does it make sense to completely rely on that and ditch the python api, or are there still benefit's?
The nose testing framework is in maintenance mode according to its official docs:
Nose has been in maintenance mode for the past several years and will likely cease without a new person/team to take over maintainership. New projects should consider using Nose2, py.test, or just plain unittest/unittest2.
Are there plans to switch to a different library or framework that is actively being developed?
I was planning to build unit tests based on the tests in this repository.
Could you add the http return/error code in the Shotgun's Exception ?
I would like to manage some exception based on 4xx and 5xx exceptions.
for instance, here I'll loose all error code :
https://github.com/shotgunsoftware/python-api/blob/master/shotgun_api3/shotgun.py#L2689
same issue here https://github.com/shotgunsoftware/python-api/blob/master/shotgun_api3/shotgun.py#L4121
but it seems _call_rpc is fine since you only do a raise at the end
Hi,
May I make a suggestion as to a slight change.
At the moment, in shotgun.py, you have the lines:
from shotgun_api3.lib.httplib2 import Http, ProxyInfo, socks
from shotgun_api3.lib.sgtimezone import SgTimezone
from shotgun_api3.lib.xmlrpclib import Error, ProtocolError, ResponseError
This means that the shotgun_api3 module has to be directly in a path in $PYTHONPATH, and can't be inside another module.
Can I suggest two things.
Firstly, that the "shotgun_api3." is removed from each of those lines, giving:
from lib.httplib2 import Http, ProxyInfo, socks
from lib.sgtimezone import SgTimezone
from lib.xmlrpclib import Error, ProtocolError, ResponseError
And secondly that, as this could conflict with something else called "lib", this folder (and these import lines) are changed to something like "shotgun_lib" or "sg_lib".
In my case, I have a module called "pipeline_core" that contains all of the core bits and pieces of my pipeline. The Shotgun API lives within this, so I need to be able to do:
from pipeline_core import shotgun_api3
Right now, this doesn't work, as the shotgun.py module inside it can't do the import. However, my suggested change will fix this.
I'm more than happy to submit a pull request for this if it is deemed appropriate.
Cheers
Hugh
Error occurring when running the unit tests on Windows with Python 2.7.8:
Error
Traceback (most recent call last):
File "C:\dev\shotgun\python_api3\tests\test_api.py", line 378, in test_share_thumbnail
shot_path = _get_path(shot_url)
File "C:\dev\shotgun\python_api3\tests\test_api.py", line 1639, in _get_path
return os.path.join(url[:4])
File "C:\Python27\lib\ntpath.py", line 64, in join
result_drive, result_path = splitdrive(path)
File "C:\Python27\lib\ntpath.py", line 115, in splitdrive
normp = p.replace(altsep, sep)
AttributeError: 'tuple' object has no attribute 'replace'
In our company, we have our own pypi source, so I build shotgun-api3 package first.
tar -xvf python-api-3.2.1.tar.gz
cd python-api-3.2.1
python setup.py sdist
Then I copy shotgun_api3-3.2.1.tar.gz to our pypi source directory.
cp dist/shotgun_api3-3.2.1.tar.gz pypi/source/shotgun_api3/
Finally, I could install shotgun-api3 by pip. But it raise an error.
pip install shotgun-api3
FileNotFoundError: [Errno 2] No such file or directory: 'LICENSE'
I think the reason is you didn't add LICENSE file to package_data but read it in setup.py.
EDIT
If I use git clone to download the source package, there is no problem. But if I download the released package, it can't work. So the problem comes from include_package_data
, because the released package doesn't have .git
folder.
I am using a python virtual environment.
I am using pip to install python-api from git:
pip install git+https://github.com/shotgunsoftware/python-api.git
....
Collecting shotgun_api3 from git+https://github.com/shotgunsoftware/python-api.git#egg=shotgun_api3
Cloning https://github.com/shotgunsoftware/python-api.git to c:\users\abcxyz\appdata\local\temp\pip-install-klwu73\shotgun-api3
Building wheels for collected packages: shotgun-api3
Building wheel for shotgun-api3 (setup.py) ... done
etc ....
The install fails with the following error:
Could not install packages due to an EnvironmentError: [Error 2] The system cannot find the file specified: 'c:\users\abcxyz\appdata\local\temp\pip-install-klwu73\shotgun-api3\tests\Noel.jpg'
When I check the directory for the Noel.jpg, I notice that the file isn't spelled Noel.jpg.
Instead it is spelled Noël.jpg . With an <ë>.
Thus, the path for \Noel.jpg fails.
Please fix this, so that I can install it into my python virtual environment.
The installation documentation contains a method that is no longer supported. This is the resulting error:
$ pip install git+git://github.com/shotgunsoftware/python-api.git
Collecting git+git://github.com/shotgunsoftware/python-api.git
...
fatal: remote error:
The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information
Installing over https works fine:
$ pip install git+https://github.com/shotgunsoftware/python-api.git
Collecting git+https://github.com/shotgunsoftware/python-api.git
...
Building wheels for collected packages: shotgun-api3
Building wheel for shotgun-api3 (setup.py) ... done
Created wheel for shotgun-api3: filename=shotgun_api3-3.3.3-py3-none-any.whl size=495076 sha256=7b85ce0030933099890695744157c7750e8532323fe5fc127d2dff959787d465
...
Successfully installed shotgun-api3-3.3.3
GitHub blog post detailing deprecation: https://github.blog/2021-09-01-improving-git-protocol-security-github/
I've been using virtualenv a lot lately to manage my web projects, and it's useful for keeping environments clean with only the required dependencies and lib versions for a project. One thing that makes using virtualenv easy is if any third party modules are installable using easy_install
.
Do you think others will want to run:
easy_install shotgun
To install the shotgun module with its dependencies? If it's done this way, there won't need to be a lib directory with third party modules hard-linked there, you can define certain modules (and versions) as dependencies, and they'll get installed as the shotgun
module is installed.
Here are the virtualenv docs: http://www.virtualenv.org/en/latest/index.html
And some info on creating python packages: http://packages.python.org/distribute/setuptools.html
Note that if this is done right, users will still be able to add it to their PYTHONPATH like it's done now.
If I get some time, I'll do some work on documenting what it would to take to turn this module into a package. What do you think?
User password and login are included in exceptions as plain text if the shotgun_api encounters an "internal error". This seems to be used in several different functions in shotgun.py. This is obviously a huge issue when storing exceptions for debugging or when using the api in programs that automatically log to an external file. An example use of it is on line 1367 - 1382:
params.update(self._auth_params())
except urllib2.HTTPError, e:
if e.code == 500:
raise ShotgunError("Server encountered an internal error. "
"\n%s\n(%s)\n%s\n\n" % (url, params, e))
Is there something i'm missing here or something I'm doing wrong?
".cache" doesn't always lead to a correct path on windows which in turn means the file isn't found:
h = Http(".cache")
see: https://github.com/shotgunsoftware/python-api/blob/master/tests/test_api.py#L339
Error
Traceback (most recent call last):
File "C:\dev\wspy\sandbox_shared\src\shotgun\python_api3\tests\test_api.py", line 309, in test_upload_thumbnail_for_task
thumb_resp, content = h.request(task_with_thumbnail.get('image'), "GET")
File "C:\dev\shotgun\python_api3\shotgun_api3\lib\httplib2\__init__.py", line 1448, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "C:\dev\shotgun\python_api3\shotgun_api3\lib\httplib2\__init__.py", line 1256, in _request
_updateCache(headers, response, content, self.cache, cachekey)
File "C:\dev\shotgun\python_api3\shotgun_api3\lib\httplib2\__init__.py", line 438, in _updateCache
cache.set(cachekey, text)
File "C:\dev\shotgun\python_api3\shotgun_api3\lib\httplib2\__init__.py", line 707, in set
f = file(cacheFullPath, "wb")
IOError: [Errno 2] No such file or directory: '.cache\\pixomondodev.shotgunstudio.com,thumbnail,api_image,150,AccessKeyId=d&Expires=xxx&Signature=xxx'
I dont believe URLError have a code attribue. HTTPError does though. HTTPError inherit from URLError. So I have doubt this case can happen here :
https://github.com/shotgunsoftware/python-api/blob/master/shotgun_api3/shotgun.py#L2668
https://docs.python.org/3/library/urllib.error.html#urllib.error.URLError
Hi,
I've just been getting very confused as to why I'm not getting the right files when I call download_attachment()
It turns out the json version is slightly different from the master branch.
In the master branch (line 889):
url = urlparse.urlunparse((self.config.scheme, self.config.server,
"/file_serve/attachment/%s" % urllib.quote(str(attachment_id)),
None, None, None))
In the JSON version (line 880):
url = urlparse.urlunparse((self.config.scheme, self.config.server,
"/file_serve/%s" % urllib.quote(str(attachment_id)),
None, None, None))
Note that the actual URL is missing 'attachment/' in the JSON version.
Without this, it gives me files, but I'm not sure what the connection is. With it, it gives me the files I would expect.
I'll put in a pull request at some point in the near future to roll this back to how it was...
If I look at a page of all of th
The param is not defined so the mocked code will raise if some call are made with it.
As the default value is True, we actually have some of our core functions that set the value to false for optim purposes.
I fixed the issue in our version of Mockgun (by adding a silly include_archived_projects=True in the function proto), but thought it was worth mentioning :)
On the breaking API thematic, the same function is also missing the additional_filter_presets one.
Did I already said I ❤️ Mockgun ?
I found that share_thumbnail() doesn't work with filmstrips unless you run it twice. Once for the static thumbnail and once for the filmstrip image :
sg.share_thumbnail(entities=[target], source_entity=source, filmstrip_thumbnail=False)
sg.share_thumbnail(entities=[target], source_entity=source, filmstrip_thumbnail=True)
If I leave out the first it won't work inside the shotgun interface.
Is that expected behaviour?
Trying to install from pip yields the following error:
$ pip install git+https://github.com/shotgunsoftware/python-api.git
Downloading/unpacking git+https://github.com/shotgunsoftware/python-api.git
Cloning https://github.com/shotgunsoftware/python-api.git to /tmp/pip-j4u7Qw-build
Running setup.py (path:/tmp/pip-j4u7Qw-build/setup.py) egg_info for package from git+https://github.com/shotgunsoftware/python-api.git
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip-j4u7Qw-build/setup.py", line 5, in <module>
f = open('README')
IOError: [Errno 2] No such file or directory: 'README'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip-j4u7Qw-build/setup.py", line 5, in <module>
f = open('README')
IOError: [Errno 2] No such file or directory: 'README'
The bug was introduced in 2dcb1b8 .
I recommend using travis-ci to check for such errors in future. One of my projects is breaking on travis now that one of it's dependencies cannot be installed anymore using the line above.
One of the imports on the embedded version of httplib2 for Python 2 was not converted to use relative imports:
It should be from .iri2uri import iri2uri
like in the Python 3 version.
Hi,
This is something I came across a while back, and just came across something similar in the GUI, so thought I'd report it.
When requesting a linked entity's image field, it won't convert the result to a URL
For example, if I want to get a Shot's details, and the linked Project's image at the same time, I feel that I should be able to do:
sg.find_one("Shot", [["id", "is", 2418]], fields = ["code", "image", "project.Project.image"])
This currently gives a result of:
{'image': 'https://protected/url/to/thumbnail.jpg', 'type': 'Shot', 'id': 2418, 'project.Project.image': 6867}
Rather than turning the Project's image into a URL
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.