Trying to get stations into Inventory using Client but failing in Linux Azure Function

Hi All,

I am creating an FDSN client to use the get_stations function to get the stations.

To do this, I am calling get_stations as follows:

        inventory = client.get_stations(latitude = latitude , longitude = longitude,
                                                maxradius = maxradius , starttime = starttime,
                                                endtime = endtime, location ="2*", channel="H*", level="response")

This runs fine locally and on windows. After deploying it to a Python Azure Function running on Linux, I am getting the following error:

 in get_relevant_stations inventory = client.get_stations(latitude = site_latitude,
 longitude = site_longitude,
 File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/clients/fdsn/",
 line 732,
 in get_stations inventory = read_inventory(data_stream) File "<decorator-gen-49>",
 line 2,
 in read_inventory File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/core/util/",
 line 300,
 in _map_example_filename return func(*args,
 **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/core/inventory/",
 line 88,
 in read_inventory return _generic_reader(path_or_file_object,
 File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/core/util/",
 line 677,
 in _generic_reader generic = callback_func(,
 **kwargs) File "<decorator-gen-50>",
 line 2,
 in _read File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/core/util/",
 line 210,
 in uncompress_file result = func(filename,
 **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/core/inventory/",
 line 97,
 in _read inventory,
 format = _read_from_plugin('inventory',
 File "/home/site/wwwroot/.python_packages/lib/site-packages/obspy/core/util/",
 line 450,
 in _read_from_plugin raise TypeError('Unknown format for file %s' % filename)Result: Failure Exception: TypeError: Unknown format for file /tmp/obspy-0yop00ed.tmp 

How can I make sure that get_stations works in my Python Azure function running on Linux? I’ve tried saving the API response in a file by specifying a filename and type. I can save this file successfully. I can also read this file manually using Python, but using ObsPy’s read_inventory function still raises the error. It’s really weird since it works properly on my local windows environment.

You’ll have to clarify. You can “read the file manually”, but you can not read with Obspy? What is “manual”? The error message indicates a broken file as most likely cause, anyway. Seems like it goes through our file format detection and none of our _is_format_xxx() routines can recognize it.

Cross posted on github:

get_stations can either save the inventory into an object, but if you specify a filename, it can save it into a file.

I was able to save it into a file and read it using open('workfile', 'w'). This worked both locally and on Azure Functions running Python. Reading this locally using ObsPy’s read_inventory function works but not when deployed on Azure Functions for Python.

Eventually, I tried different Setups for Azure Functions Environments. I was running it on a consumption plan which is where I was experiencing all those issues. Running it on the Dedicated (App Service) B3 tier Plan worked and I was able to get the same output I was getting locally. There might some limitations for Azure Functions running on a consumption plan. I’m currently trying different setups and it seems like running it on a dedicated plan is a fix.

1 Like