Jump to content

Location crashes on get_url(...)


Jakub Trllo

Recommended Posts

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!

Link to comment
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)
Link to comment
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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...