File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -121,21 +121,19 @@ def invenio_server_name(server_url):
121121 server_host = netloc (server_url )
122122 endpoint = '/api/records?size=1'
123123 try :
124- log (f'testing if we can reach { server_url } in 5 sec or less' )
125- socket .setdefaulttimeout (5 )
126- # If the next one can't reach the host, it'll throw an exception.
127- socket .socket (socket .AF_INET , socket .SOCK_STREAM ).connect ((server_host , 443 ))
128- # If we can reach the host, check that it responds to the API endpoint.
129124 if response := network ('get' , server_url + endpoint ):
130125 log (f'we can reach { server_url } and it responds to { endpoint } ' )
131126 data = response .json ()
132- record = data .get ('hits' , {}).get ('hits' , {})[0 ]
133- if publisher := record .get ('metadata' , {}).get ('publisher' ):
134- return publisher
127+ records = data .get ('hits' , {}).get ('hits' , {})
128+ if records :
129+ if publisher := records [0 ].get ('metadata' , {}).get ('publisher' ):
130+ return publisher
131+ else :
132+ # Fall back to the host name
133+ return server_host
135134 else :
136135 # Fall back to the host name.
137136 return server_host
138- return record ['metadata' ]['publisher' ]
139137 except KeyboardInterrupt :
140138 raise
141139 except socket .error :
You can’t perform that action at this time.
0 commit comments