Location crashes on get_url(...)
1 1

8 posts in this topic

Hi, I'm trying out how to download images from notes but when I want call Location.get_url(note_component[component]), session crashes with: AttributeError: 'Symbol' object has no attribute 'get_url'.

I've found out that "ftrack.server"'s Location accessor stays set to ftrack_api.symbol.NOT_SET. When I tried same code for "ftrack.unmanaged" it worked correctly. Can you help me what can be wrong on my side?

Thanks!

Share this post


Link to post
Share on other sites

Hi, I've actually tried API documentation part:

```

server_location = session.query(
    'Location where name is "ftrack.server"'
).one()

for note_component in note['note_components']:
    print 'Download URL: {0}'.format(
        server_location.get_url(note_component['component'])
    )

```

Share this post


Link to post
Share on other sites

Hi Jakub,

Can you provide a simplified code to show the issue?
In case it contains sensitive information, please send it to support.

Regards,
Johan

Share this post


Link to post
Share on other sites

I've cut off all unnecessary parts of code and modified it to the most basic script that should work(i think):

import ftrack_api

session = ftrack_api.Session(
    auto_connect_event_hub=True,
    server_url='https://myapp.ftrackapp.com',
    api_key='xxx-xxx-xxx-xxx-xxx',
    api_user='my.user.name'
)

server_location = session.query(
    'Location where name is "ftrack.server"'
).one()

# just pretend that note with component will be queried...
note = session.query('Note').first()

for note_component in note['note_components']:
    component = note_component['component']
    download_url = server_location.get_url(component) # This is line where error is raised
    path = r'C:\Users\my.user.name\test' + component['file_type']
    download_file(download_url, path)

def download_file(url, path):
    r = requests.get(url, stream=True).content
    with open(path, 'wb') as f:
        f.write(r)

Share this post


Link to post
Share on other sites

Hi @Jakub Trllo, I've just tried the code you sent and cannot get to reproduce your issue.

Here is what I've been doing and the code I've used.

1) I have manually created a note on a task from the web interface.
2) I have run the following code to add a component to the given note (please "note", that I have just one , so the query is quite simple).
 

import ftrack_api

session = ftrack_api.Session()

server_location = session.query(
    'Location where name is "ftrack.server"'
).one()

note = session.query('Note').first() # get the only note I have in the system

# Create component and name it "My file".
component = session.create_component(
    '/path/to/an/image.png',
    data={'name': 'My file'},
    location=server_location
)

# Attach the component to the note.
session.create(
    'NoteComponent',
    {'component_id': component['id'], 'note_id': note['id']}
)
session.commit()

Once run this code I then run this other snippet :

 

import ftrack_api


session = ftrack_api.Session(
    auto_connect_event_hub=True,
)

server_location = session.query(
    'Location where name is "ftrack.server"'
).one()

# just pretend that note with component will be queried...
note = session.query('Note').first()

for note_component in note['note_components']:
    component = note_component['component']
    download_url = server_location.get_url(component)
    print download_url # I just print the path as the issue seems on retrieving it.

When running the above code this is the result I'm getting:

https://myserver.ftrackapp.com/component/get?id=d5d785dc-fdd0-4c6f-b7f9-54b3339ade81&username=myuser&apiKey=m1ap1key-m1ap1key-m1ap1key-m1ap1key-m1ap1key


Hope it helps.
L.

Share this post


Link to post
Share on other sites

Found out the mistake I've made because of you.

I am using same session for all actions. Seems like not good idea when working with "ftrack.server" location, loose it's definition (probably on session.reset()?).

 

Thanks

Share this post


Link to post
Share on other sites

Hi @Jakub Trllo glad to hear you had it sorted!
If you can produce a piece of code that crashes I'd like you to send it to support for further checks if you don't mind :)
Thanks a lot, and if there's anything else we can help out with, just let us know ! 
L.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
1 1