Azure function failing after successfull deployment with OSError: [Errno 107] - python

The function was working before the last deployment. It is used for NLC and we are running two functions for two different languages. For the new deployment we removed some code which was only used for one language and mirrored the code to be equal to the other language. Azure CLI tells us:
Upload completed successfully.
Deployment completed successfully.
But when trying to invoke the function afterwards it either returns 500 without a body or it returns 404 with:
<html>
<head>
<title>404 Not Found</title>
</head>
<body bgcolor="white">
<center>
<h1>404 Not Found</h1>
</center>
<hr>
<center>nginx</center>
</body>
</html>
The stacktrace we can see in the monitoring is the following:
Exception while executing function: Functions.classify Result: Failure
Exception: OSError: [Errno 107] Transport endpoint is not connected: '/home/site/wwwroot/.python_packages/lib/site-packages'
Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 271, in _handle__function_load_request
func = loader.load_function(
File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call
return func(*args, **kwargs)
File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/classify/__init__.py", line 4, in <module>
File "/home/site/wwwroot/classify/predict.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/text/all.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/basics.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/data/all.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/torch_basics.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/torch/__init__.py", line 482, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/torch/serialization.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 914, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1342, in find_spec
File "<frozen importlib._bootstrap_external>", line 1314, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1443, in find_spec
File "<frozen importlib._bootstrap_external>", line 1483, in _fill_cache
Commands used for deployment were the following, which worked before:
pip3 install --target="./.python_packages/lib/site-packages" -r requirements.txt
func azure functionapp publish [functionapp name] --no-build
Deleting the python packages and rebuilding etc. did not change anything.
I tried creating a new function app from scratch but it shows the same errors.
I tried to deploy from the folder of the other language with one file swapped (classifier language model) but it
showed the same error. I fear trying to redeploy the working language
for testing as it is working and I don't want to kill it.

It seems to be happening somewhere during module import. Though I am not sure how it was working before (as you mentioned), but I suggest you not to do pip3 install manually and remove --no-build flag to let the func azure functionapp publish handle that. Just make sure you have the requirements.txt in the root.
# no pip install manually
# without --no-build flag
func azure functionapp publish [functionapp name]

Related

Missing zxJDBC connector in sqlalchemy (With DB2)

Facing issue with a sqlalchemy + db2(remote server) application.
Dependency installed:
SQLAlchemy==1.4.21
ibm-db==3.0.4
ibm-db-sa==0.3.6
python version = 3.8
Here is the connection snippet:
self.__engine = create_engine(f'ibm_db_sa://{DB2_USER}:{DB2_PASSWD}#{DB2_INSTANCE}/{DB2_DB}')
Seeing below issue:
File "/db-query-service/query_executor/db_reader/db2_reader_with_query.py", line 19, in __init__
self.__engine = create_engine(f'ibm_db_sa://{DB2_USER}:{DB2_PASSWD}#{DB2_INSTANCE}/{DB2_DB}')
File "<string>", line 2, in create_engine
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
return fn(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/create.py", line 522, in create_engine
entrypoint = u._get_entrypoint()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/url.py", line 653, in _get_entrypoint
cls = registry.load(name)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 337, in load
return impl.load()
File "/usr/local/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.8/site-packages/ibm_db_sa/__init__.py", line 22, in <module>
from . import ibm_db, pyodbc, base, zxjdbc
File "/usr/local/lib/python3.8/site-packages/ibm_db_sa/zxjdbc.py", line 32, in <module>
from sqlalchemy.connectors.zxJDBC import ZxJDBCConnector
ModuleNotFoundError: No module named 'sqlalchemy.connectors.zxJDBC'
Questions:
Is there any dependency missing or mismatch in versions?
Is there any issue with sqlalchemy installation? - I removed and reinstalled it to rule that out.
Able to work with Mysql remote db.
zxjdbc is specific to jython i found, will db2+ Sqlalchemy work with jython implementations.?
If db2+ Sqlalchemy work with cpython, what's the fix for the issue?
Reference Doc:
Here is the link
Temporarily, you need to uninstall the sqlalchemy 1.4.x and as a workaround, then install the current sqlalchemy 1.3.x release . At today's date this is sqlalchemy 1.3.24 which should resolve the issue.
I expect this problem will eventually get resolved.
Link to issue is here

I get "bad file descriptor" error when i try to run pip commands [duplicate]

whenever i try to install pip i always get this error. pls help . i dont know how to fix this i tried doing it using the default python executable using the modify method and also tried the get-pip.py file method nothing works. i have checked my path variables too so the scripts folder is there but pip is not installed.
PS C:\Users\ismai\Desktop\programs\PYTHON> python get-pip.py
Traceback (most recent call last):
File "C:\Users\ismai\Desktop\programs\PYTHON\get-pip.py", line 23704, in <module>
main()
File "C:\Users\ismai\Desktop\programs\PYTHON\get-pip.py", line 198, in main
bootstrap(tmpdir=tmpdir)
File "C:\Users\ismai\Desktop\programs\PYTHON\get-pip.py", line 83, in bootstrap
from pip._internal.commands.install import InstallCommand
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_internal\commands\install.py", line 17, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_internal\cli\req_command.py", line 16, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_internal\index\collector.py", line 14, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\__init__.py", line 125, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\utils.py", line 27, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\_internal_utils.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\compat.py", line 65, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 786, in exec_module
File "<frozen importlib._bootstrap_external>", line 922, in get_code
File "<frozen importlib._bootstrap_external>", line 980, in get_data
OSError: [Errno 9] Bad file descriptor
I actually had a similar problem and tried every possible solution, the only one which worked with me is to uninstall python and reinstall it in different partition other than the C , it will work !
Go to the folder in which you Python installer is there and click on it. It will open the installer and show "modify setup":
Uninstall python and then download it from https://www.python.org/downloads/ reinstall it and make sure to check the box that adds pip to PATH.
Ok guys i tried unistalling this new version(3.9) and then installed an old version(3.7) and then ran the command python get-pip.py and magically it worked. if anyone in future wants to fix this issue then try this. i also read the python documenttion and apparantly they have a command if pip isnt installed on your version of python that is python -m ensurepip so you can try that too.
And then click on "Uninstall". After uninstall done click on close and again go to your installer and click on it and after that it will show like this.
After check Add python to PATH and click on "customize installation". Check everything in advanced option and click install.
Done!

AttributeError: module 'pip._internal.download' has no attribute 'HTTPAdapter'

I recently upgraded my pip to 19.3. When I did that I cannot use any pip commands. OS - Mac
When I googled and researched more, most of the suggestions were to downgrade the pip package. However, even when I tried that I am getting the same result. In fact, force installs or uninstall or sudo commands nothing works.
Traceback (most recent call last):
File "/Users/.virtualenvs/myvenv/bin/pip", line 10, in <module>
sys.exit(main())
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/main.py", line 45, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 21, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 17, in <module>
from pip._internal.download import unpack_url
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/wrapt/importer.py", line 158, in load_module
notify_module_loaded(module)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/wrapt/decorators.py", line 443, in _synchronized
return wrapped(*args, **kwargs)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/wrapt/importer.py", line 136, in notify_module_loaded
hook(module)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip_system_certs/wrapt_pip.py", line 8, in apply_patches
override_ssl_handler(download)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip_system_certs/wrapt_pip.py", line 17, in override_ssl_handler
class SslContextHttpAdapter(download.HTTPAdapter):
AttributeError: module 'pip._internal.download' has no attribute 'HTTPAdapter'
Can somebody help, please?
This appears to be because you installed the pip-system-certs package, which hooks into pip internals in a way that was never supported. This promptly broke as soon as you updated pip and the stuff pip-system-certs wanted to mess with got changed.
You will at least need to get rid of pip-system-certs. It looks like it was installed in a virtualenv, so you can probably just deactivate the env and make a new one... but if so, it seems like you would have already tried that. If you didn't already try that, make sure to try it next time! If you did already try that, then you probably wrecked more stuff than we can see, and you may need more drastic measures, such as a full Python reinstall.
What worked for me was to go to <your conda environment>\Lib\site-packages and remove all occurences of pip-system-certs. In my case it was one file and two folders.
pip-tools~=4.2.0 is compatible with pip>=19.3

Installing Scapy on Android

I did an installation on android using the follow commands on android:
apt install python
pip install scapy
everything is fine for now, but when i run scapy i got this error -----see error
This error does not happen to me in conda or kali, it appears to be exclusive for android.
ERROR: Loading module scapy.layers.netflow
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/main.py", line 143, in _load
mod = importlib.import_module(module)
File "/data/data/com.termux/files/usr/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/layers/netflow.py", line 112, in <module>
class NetflowRecordV5(Packet):
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/layers/netflow.py", line 127, in NetflowRecordV5
ByteEnumField("prot", IP_PROTOS["tcp"], IP_PROTOS),
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/dadict.py", line 49, in getitem
return getattr(self, attr)
AttributeError: 'DADict' object has no attribute 'tcp'
The android device is rooted. I hope someone is familiar with this error and can help. Thanks
i did this on my phone but it looks require root access

Failed executing Azure App Function (Python) after publishing to Azure. 'No module named <n>'. Works locally

I have a python function that I've created as an Azure App Function. It works on my local machine fine, however fails with no descriptive error when executed after a successful publishing.
Originally, it failed with 500 internal server error due to:
Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'
Stack: File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 218, in _handle__function_load_request
func_request.metadata.entry_point)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/loader.py", line 66, in load_function
mod = importlib.import_module(fullmodname)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/generateGraph/__init__.py", line 2, in <module>
import pandas as pd
I thought this was me not publishing with the --build-native-deps switch. So I republished with this switch: (.env) C:\Temp\python_function>func azure functionapp publish httpGenGraph --build-native-deps
And publishing was successful. Now, when I execute the Http Trigger, I get the same error again. Is there something I'm missing? I'm new to Python so it could be not understanding the packaging requirements or something. The function does work within my local virtual python environment.
Figured it out. I needed to pipe the output of pip freeze to the requirements.txt file. This allowed the packages to be properly referenced when publishing.
For reference:
(.env) C:\Temp\python_function>pip freeze > requirements.txt
Then:
(.env) C:\Temp\python_function>func azure functionapp publish httpGenGraph --build-native-deps

Categories