SpeckleException: SpeckleException: Failed to execute the GraphQL commit request. Inner exception: 403 Client Error: Forbidden for url: https://speckle.xyz/graphql
AttributeError: 'SpeckleException' object has no attribute 'referencedObject'
why is it so difficult to authenticate and extract data??
import streamlit as st
from specklepy.api.client import SpeckleClient
from specklepy.api.wrapper import StreamWrapper
def main():
st.title("Stream Access Test")
token = st.text_input(
"Enter your Speckle token:",
"{{TOKEN}}", # don't share your token with anyone!!
)
stream_url = st.text_input(
"Enter your Speckle Stream:",
"https://speckle.xyz/streams/{{STREAM_ID}}",
)
# This now uses the StreamWrapper to shortcut from URL
# to all the details we need
wrapper = StreamWrapper(stream_url)
host = wrapper.host
stream_id = wrapper.stream_id
client = SpeckleClient(host)
client.authenticate_with_token(token)
if client.account.token is not None:
# This checks that we authenticate as the user we expected
st.write(f"Client: {client} ({client.user.account.userInfo.email})")
else:
st.write(
f"Client: {client} ({client.user.account.userInfo.email})",
"Invalid token"
)
return
stream = client.stream.get(stream_id)
st.write("Stream: " + str(stream))
if __name__ == "__main__":
main()
I noticed your example code was defaulting to an ancient token from @gokermu - lets omit that - always good advice to keep those tokens private!!
The tester script revealed for me that under one pyenv, that specklepy was always resolving to the local default account, regardless of authenticating with the token; this only really affects you if you have a number of accounts and servers, but it did cause me some consternation for a short while.
@jonathon thanks mate. This example works, but so did the previous example I had shared until that point (finally!).
It is when I try to take the script ‘further’, i.e. start interrogating data, that receive the error AttributeError: 'SpeckleException' object has no attribute 'referencedObject'
right so which version of which code are we working to get working - as that should be all you need, but I lost track with your posts of both code and tutorials that were different things?
I have a hunch that streamlits data caching may be an arse here, but I’m not a streamlit expert
1. Getting stream and authorising via a token
which was returning the specklepy.logging.exceptions.GraphQLException: error: I have solved that by deleting my personal access token (streams:read apparently was not sufficient) and recreating a new one with everything authorised. I have also tested your minimum example on that and it works well - thanks!
2. Extracting data
Whatever happens later is a bit unclear to me.
I consider myself decent in python and ok with streamlit, but all the object retrieval using the commits and everything happening after that is still a bit confusing for me.
From another tutorial example @gokermu posted ( https://speckle.systems/tutorials/create-your-first-speckle-app-using-only-python/ it seems this can be chosen within the app menus, so it may be a question to mix and match the code from the two.
Specifically here the issue is that the following code section:
# COMMIT 🍀
# gets a commit given a stream and the commit id
commit = client.commit.get(wrapper.stream_id, wrapper.commit_id)
# get obj id from commit
obj_id = commit.referencedObject
# receive objects from commit
commit_data = operations.receive(obj_id, transport)
returns the error: AttributeError: 'SpeckleException' object has no attribute 'referencedObject'
and this happened when I ran the example file (main.py) provided by @gokermu
@jonathon yes it looks like. Thanks for your help. I thing I have figured out a couple of things re: authorising as the two examples from @gokermu provide two alternative methods ( client = SpeckleClient() and wrapper = StreamWrapper(commit_url). For instance I managed to get the first method to work, but the second only worked when the Speckle connector was open and logged in on my computer.
Yes, StreamWrapper uses your local account(stored in Manager for Speckle) in the background for authentication. But all other functionalities(getting stream id/commit id from URL etc.) should still work.