hydroshare / hs_restclient

Python client for the https://www.hydroshare.org REST API
BSD 3-Clause "New" or "Revised" License
6 stars 8 forks source link

Received status 504: Gateway Time-out #124

Closed amabdallah closed 3 years ago

amabdallah commented 4 years ago

Hi @sblack-usu and @Castronova

Any clue why I'm getting this error message? It's the very basic code to access my account

username = 'username'

password = 'password'

auth = HydroShareAuthBasic(username=username, password=password)

hs = HydroShare(auth=auth)

for resource in hs.resources(): print 'Connected to HydroShare'

Traceback (most recent call last): File "C:/Users/Rosenberg/Documents/GitHub/WaMDaM_Wizard_1.05-2.7/src/controller/HydroShare/trash.py", line 13, in for resource in hs.resources(): File "C:\Python27\lib\site-packages\hs_restclient\generators.py", line 12, in resultsListGenerator raise HydroShareHTTPException(r) hs_restclient.exceptions.HydroShareHTTPException: Received status 504

504 Gateway Time-out

504 Gateway Time-out


nginx/1.11.13

when accessing https://www.hydroshare.org/hsapi/resource/ with method GET.

image

sblack-usu commented 4 years ago

that endpoint performs terribly when no filters are provided. Try listing just published resource

for resource in hs.resources(published=True):
    print(resource)

This is an issue we're working through, but filtering your resources will help you for now.

amabdallah commented 4 years ago

@sblack-usu thank you, it worked. What I'm trying to do as a first step here is just to connect to hs and validate user credentials. Is there a better way to do that? Ideally there should be a parameter coming back with valid or invalid connection value and I can just look into it without needing to do this hs.resources().

I added a break, for now, to stop the for loop after getting the first resource which implicitly means the credentials are valid

for resource in hs.resources(published=True): print("success") self.btn_login.Enabled = False break

Castronova commented 4 years ago

@amabdallah Take a look at how I validate user credentials in the hstools application: https://github.com/Castronova/hstools/blob/master/hstools/auth.py. After I instantiate a connection with HydroShare, I make a simple getUserInfo request. This request raises an exception if the login failed

try:
    a = hs_restclient.HydroShareAuthBasic(username=creds['usr'], password=creds['pwd'])
    hs = hs_restclient.HydroShare(auth=a)
    hs.getUserInfo()
    return hs
except Exception as e:
    raise Exception(e)
Castronova commented 4 years ago

that endpoint performs terribly when no filters are provided. Try listing just published resource

for resource in hs.resources(published=True):
    print(resource)

This is an issue we're working through, but filtering your resources will help you for now.

@sblack-usu Not sure if you saw this in the HydroShare project, but we might need to take a close look at the resource filtering logic. It appears that the published filter is returning non-published resources: https://github.com/hydroshare/hydroshare/issues/3868

sblack-usu commented 4 years ago

https://github.com/hydroshare/hydroshare/pull/3880 addresses the performance of the resources endpoint. It will be included in the next release in the coming weeks.