Python Requests Module Error

Hi, We are trying to call a SaaS API call with Python. and I installed Python 3.9 as well as the requests module. but I met some runpy.py error- saying no requests module found.

Can you please suggest what are needed?

Thank you!
Rachel

Z:>pip show requests
Name: requests
Version: 2.26.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: c:\users\racheldo-admin\appdata\roaming\python\python39\site-packages
Requires: certifi, idna, charset-normalizer, urllib3
Required-by:

Z:>python -c “import requests;print(requests.version)”
2.26.0

The step failed: Activity Request to put avoka into Maintenance mode on the Octopus Server failed with error ‘The remote script failed with exit code 1’.

Octopus Server

Ran for 5 seconds

December 3rd 2021 13:53:01

Error

Traceback (most recent call last):

December 3rd 2021 13:53:01

Error

File “E:\Octopus\Work\20211203215255-101299-336\Bootstrap.76a-491c-b70d-579a0eaad875.Script.py”, line 3, in

December 3rd 2021 13:53:01

Error

run_path(“E:\Octopus\Work\20211203215255-101299-336\Script.py”, configuration)

December 3rd 2021 13:53:01

Error

File “C:\Program Files (x86)\Python39-32\lib\runpy.py”, line 268, in run_path

December 3rd 2021 13:53:01

Error

return _run_module_code(code, init_globals, run_name,

December 3rd 2021 13:53:01

Error

File “C:\Program Files (x86)\Python39-32\lib\runpy.py”, line 97, in _run_module_code

December 3rd 2021 13:53:01

Error

_run_code(code, mod_globals, init_globals,

December 3rd 2021 13:53:01

Error

File “C:\Program Files (x86)\Python39-32\lib\runpy.py”, line 87, in _run_code

December 3rd 2021 13:53:01

Error

exec(code, run_globals)

December 3rd 2021 13:53:01

Error

File “E:\Octopus\Work\20211203215255-101299-336\Script.py”, line 3, in

December 3rd 2021 13:53:01

Error

import requests

December 3rd 2021 13:53:01

Error

ModuleNotFoundError: No module named ‘requests’

December 3rd 2021 13:53:01

Fatal

The remote script failed with exit code 1

December 3rd 2021 13:53:01

Fatal

The action Request to put avoka into Maintenance mode on the Octopus Server failed

Hi Rachel,

Thanks for posting your question!

Could you let me know a little more about how your process is configured? It might be best if you can send me a JSON output of your process, which you can upload securely for me to review with the following link: Support - Octopus Deploy

Otherwise, I was wondering how you have your step configured with regards to where this script is running? For example, the following would run the script on the deployment target:

Depending on where the script executes (e.g. a local worker on the Octopus server), you’ll need to make sure Python and the proper libraries are set up there.

Lastly, are you using execution containers for this process?

Looking forward to hearing back from you on the above!

Best,
Patrick

Hey Patrick, thank you for your response.

I haven’t configure anything with docker or container yet. and this is running on Octopus server. For this simple task we are calling a SaaS Api inside the python script with basic authentication method. So we pass the user name and password directly and do a post action and hope the response body will give me 200.

We have installed python and it was recognized. The requests module - however is not recognized. Python and its library are installed globally for all users. But I am not familiar with how Octopus runs Python, does it request the module to be installed by each process step?

Hope it makes senses.
Thank you!
Rachel

Hey @rachel.dong,

Unfortunately, I wasn’t able to reproduce this issue.

I installed Python 3.10 on a Virtual Machine with an Octopus Server on the same box.

When running this in CMD: ‘python -c "import requests;print(requests.__version__)"
I received the response: 2.26.0

This was also the same response I got when running the command inside Octopus via the ‘Run a Script’ step as PowerShell calling Python and also Python directly.

Are you able to run the script on the target in PowerShell via Octopus but start with:
pip list

This will allow us to confirm that the user environment on the target does have the module required, as, in your OP, it mentions the install directory being your own user profile:
Location: c:\users\racheldo-admin\appdata\roaming\python\python39\site-packages

Lastly, would you be able to let me know what Octopus Server version you’re running as it may have a part to play in being able to reproduce this issue if there are no other causes?

Thanks and Kind Regards,
Adam

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.