Is speckle.xyz accessible from specklepy?

I’ve promised myself fewer rabbit hole adventures this year, so I’ll just ask…

I’ve not touched python for a few years and was just dusting it off for new years eve playtime and hit an immediate roadblock. It doesn’t seem likely that default server isn’t accessible from specklepy so am I missing something super basic? Environment variables?

# the speckle.objects module exposes all speckle provided classes
from specklepy.api.client import SpeckleClient
from specklepy.api.credentials import get_local_accounts, get_default_account

class Reader(object):
    
    def __init__(self):
        # initialise the client
        client = SpeckleClient(host="speckle.xyz",use_ssl=True) # default is xyz

and …

Python Exception <SpeckleException>: SpeckleException: https://speckle.xyz is not a compatible Speckle Server
1 Like

@jsdbroughton

hi, i just checked and the speckle.xyz server is online, and the code that you mentioned works on my machine.

To investigate further, can you open https://speckle.xyz/ in your browser successfully?

Also, the exception should have an inner exception. Can you paste it fully?

2 Likes

thanks @cristi I can access xyz yes.

Python Exception <SpeckleException>: SpeckleException: https://speckle.xyz is not a compatible Speckle Server
Traceback (most recent call last):
  File "…/specklepy/api/client.py", line 81, in __init__
    raise Exception("Couldn't get ServerInfo")
Exception: Couldn't get ServerInfo
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<string>", line 37, in input
  File "…/specklepy/api/client.py", line 83, in __init__
    raise SpeckleException(f"{self.url} is not a compatible Speckle Server", ex)
specklepy.logging.exceptions.SpeckleException: SpeckleException: https://speckle.xyz is not a compatible Speckle Server

This may not be a speckle question. I have successfully written a more featured script beyond simply authenticating. This is running on the base installation of python on my machine.

It is running this script within the PythonCaller environments of FME that is raising the error, so I’ll raise it with them to see what might be at the root.

It also works with the FME python REPL, so I’m looking into whether certain transports are possible from the PythonCreator/PythonCaller transformers.

1 Like

Hmm, looks like there is an error making an initial graphql request to check the server.

The error handling could be improved to show what actually happened, but until we do that, could you run the following code to see the details of what went wrong doing the graphql request?

from specklepy.api.client import SpeckleClient

obj = object.__new__(SpeckleClient)
try:
    obj.__init__()
except Exception as ex:
    print('the error happened, ignoring')

print(obj.server.get())
1 Like
the error happened, ignoring
SpeckleException: Failed to execute the GraphQL server request. Inner exception: Transport is already connected

Hmm,

I looked a bit into this and my guess is that it’s related to missing HTTPS certificates in the PyhtonCaller environment ( in their forum they recommend to ignore certificates completely: FME Community )

I’ll ping @izzylys for thoughts about this, most probably we will have to do in-depth testing on PythonCaller environment to have basic support for it (even if it means ignoring https certificates?)

1 Like

Much appreciated @cristi (& @izzylys) In fact, I’m happy to make the looking into this and liaise with the FME people.

My first post motivation was to not do any unnecessary digging in case it was a simple problem I was missing. So often I get sucked into impossible missions having stumbled onto edge cases due to something dumb.

Thanks for looking!

Question posted to the FME forum

1 Like

One more thought about this, to check if it’s related to urllib3 / requests version incompatibilities with gql library.

Can you run this to check if it has any errors? (on success, it should output the 200 status code and the server version in a json, currently at 2.3.6)

from specklepy.api.client import SpeckleClient

import requests
from requests.adapters import HTTPAdapter, Retry


session = requests.session()
adapter = HTTPAdapter(
    max_retries=Retry(
        total=3,
        backoff_factor=0.1,
        status_forcelist=[500, 502, 503, 504],
        allowed_methods=None,
    )
)
for prefix in "http://", "https://":
    session.mount(prefix, adapter)

response = session.post('https://speckle.xyz/graphql', json={'query': '{serverInfo{version}}'})
print(response.status_code)
print(response.text)

Success of sorts then.

200
{"data":{"serverInfo":{"version":"2.3.6"}}}

Incidentally, the allowed_methods keyword argument wasn’t known so this worked only if this was removed

that would point to urllib then, yes

Curiously, the urllib3 installed within FME is as latest so the class signature should allow that keyword.

UPDATE
I’m already into working out the runtime dependency loading of FME as the urllib library in the plugins folder is 1.26.7, but at runtime, the version is 1.25.7 hence the missing signature.

1 Like

Oh, so this should explain the initial error, because gql library uses the allow_methods field that was introduced in urllib3 from version 1.26.0.

So the issue is not related to certificates, but to this incompatible urllib3 version

Glad we got to the bottom of this :slight_smile: I’m not sure about how to update urllib3 inside the FME env

1 Like

i’m on it. i think i have an idea.

it will mean a more extensive README to the repo :smiley:

1 Like
--------
SpeckleClient( server: https://speckle.xyz, authenticated: True )
--------

:metal:

2 Likes

A bit hacky for now as I’m installing new packages within the base application package and rebuilding FME

$> fme python -m pip install requests --target '/Library/FME/<version:yyyy.x>/python'Python
$> fme python -m pip install urllib3 --target '/Library/FME/<version:yyyy.x>/python'

Who knows which transformers this will break :grimacing:

but…

--------
SpeckleClient( server: https://speckle.xyz, authenticated: True )
--------

:metal:

What I’ll follow up with FME is how to address alternative libraries within PythonCaller - definitely not a speckle issue!

4 Likes