简体   繁体   English

在 azure webjob 导入 python 模块

[英]Importing python modules in azure webjob

I have been attempting to deploy a web scraper written in python for the past few weeks on azure. I initially tried to do this in an azure app service by building pushing a docker image to the service.在过去的几周里,我一直在尝试在 azure 上部署一个用 python 编写的 web 爬虫。我最初尝试在 azure 应用程序服务中通过构建将 docker 图像推送到服务来实现这一点。 I have had success previously with this method when deploying a flask rest api. Unfortunately the time out limit of the azure app service meant that the web scraper container is terminated as it is does not give a proper response when azure attempts to get a response - this option won't work.我以前在部署 flask rest api 时使用此方法取得了成功。不幸的是,azure 应用程序服务的超时限制意味着 web 刮板容器已终止,因为当 88337235 到 20088 时它没有给出正确的响应此选项将不起作用。

I have since tried setting up a windows based app service in order to create an azure WebJob however, this has the problem of being capped at python 3.6 which i believe is causing import problems.从那以后,我尝试设置一个基于 windows 的应用程序服务以创建一个 azure WebJob 但是,这有一个问题,即上限为 python 3.6,我认为这会导致导入问题。 I cannot import the "requests" module which is essential for the scraper to work correctly.我无法导入爬虫正常工作所必需的“请求”模块。 I have a requirements.txt inside the zip i upload for the webjob but this doesnt seem to allow the importing of this module either.我为 webjob 上传的 zip 中有一个 requirements.txt,但这似乎也不允许导入该模块。 Is there a way to import modules from inside the webjob?有没有办法从 webjob 中导入模块?

Below is the error i am receiving in the webjob logs:以下是我在 webjob 日志中收到的错误:

[12/19/2020 16:36:48 > 658fd3: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost'
[12/19/2020 16:36:48 > 658fd3: SYS INFO] Status changed to Running
[12/19/2020 16:36:48 > 658fd3: ERR ] Traceback (most recent call last):
[12/19/2020 16:36:48 > 658fd3: ERR ]   File "run.py", line 12, in <module>
[12/19/2020 16:36:48 > 658fd3: ERR ]     import requests
[12/19/2020 16:36:48 > 658fd3: ERR ] ModuleNotFoundError: No module named 'requests'

I have been attempting to deploy a web scraper written in python for the past few weeks on azure.过去几周,我一直在尝试在 azure 上部署用 python 编写的 web 刮板。 I initially tried to do this in an azure app service by building pushing a docker image to the service.我最初尝试通过构建将 docker 图像推送到服务来在 azure 应用服务中执行此操作。 I have had success previously with this method when deploying a flask rest api.我以前在部署 flask rest api 时使用此方法取得了成功。 Unfortunately the time out limit of the azure app service meant that the web scraper container is terminated as it is does not give a proper response when azure attempts to get a response - this option won't work.不幸的是,azure 应用程序服务的超时限制意味着 web 刮板容器被终止,因为当 azure 尝试获得响应时,它没有给出正确的响应。

I have since tried setting up a windows based app service in order to create an azure WebJob however, this has the problem of being capped at python 3.6 which i believe is causing import problems.此后,我尝试设置基于 windows 的应用程序服务以创建 azure WebJob,但是,这有一个问题,即被限制在 python 3.6 上。 I cannot import the "requests" module which is essential for the scraper to work correctly.我无法导入对刮板正常工作至关重要的“请求”模块。 I have a requirements.txt inside the zip i upload for the webjob but this doesnt seem to allow the importing of this module either.我在为网络作业上传的 zip 中有一个 requirements.txt,但这似乎也不允许导入此模块。 Is there a way to import modules from inside the webjob?有没有办法从 webjob 内部导入模块?

Below is the error i am receiving in the webjob logs:以下是我在 webjob 日志中收到的错误:

[12/19/2020 16:36:48 > 658fd3: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost'
[12/19/2020 16:36:48 > 658fd3: SYS INFO] Status changed to Running
[12/19/2020 16:36:48 > 658fd3: ERR ] Traceback (most recent call last):
[12/19/2020 16:36:48 > 658fd3: ERR ]   File "run.py", line 12, in <module>
[12/19/2020 16:36:48 > 658fd3: ERR ]     import requests
[12/19/2020 16:36:48 > 658fd3: ERR ] ModuleNotFoundError: No module named 'requests'

Search Advanced Tools in Filter.在过滤器中搜索高级工具。 Click on the GO Link.单击 GO 链接。 Then choose Debug Console and click on CMD.然后选择调试控制台并单击 CMD。

Find your Source Code directory path.找到您的源代码目录路径。 Then type in the path:然后输入路径:

python -m pip install - requirements.txt
d:\ |-- home
      |-- site
          |-- wwwroot
              |-- App_Data
                  |-- jobs
                      |-- triggered
                      | -- continuous

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM