Cgi programming with python - python

I am trying to execute a python cgi script which is having a bash script that logs into remote servers to get logs. This log is seen in browser.
I am able to run this script from terminal and get expected result. Whereas trying to run this script over a browser. There is no result a blank page shows up.
After lot of analysis found that When running from browser it runs as apache user who does not have permission to login to remote servers.
I want to make it run as a particular user is that possible ?

Related

Linux Crontab Python script error: "Authorization required, but no authorization protocol specified"

let me explain the problem in detail:
I have a Windows 10 desktop, from which i connect via RDP (same LAN) to a laptop running Kali Linux 2022.3.
On this laptop, i have Conda and Spyder for developing some webscraping Python scripts.
I developed a web scraping script that simulate a user navigate to a site, logging in, upload a document and log out (this is to iterate some real-work stuff).
In my script i use selenium and pyautogui.
In my testing process:
from desktop i RDP to laptop
from laptop (i login with root) i open spyder
i run the script (chromedriver in headless mode, altough i tested it also in viewable mode).
everythings run just fine. it open the browser, login, upload the file and logout. (also in headless mode the test succeed, i see no browser BUT i have a mail confirmation that the script ran successfuly).
The problem comes when i try to schedule the script via crontab.
I made a scraper.sh with:
/path_to_python/ /root/path_to_script.py >> /root/out_err.txt 2>&1
And then, in crontab i put the line (i want the script to run at 15 every 2 day):
00 15 */2 * * /root/scraper.sh
I wait connected to the laptop until the script fires, and of course the script RUN, but does nothing. So i go to the the out_err file, and i find:
File "/root/anaconda3/lib/python3.9/site-packages/Xlib/protocol/display.py", line 129, in __init__
raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
I am stuck at this point, where my knowledge fail me ;-)
Can anyone help? Thank You very much.
David

Unable to run python(Selenium) code on UI while embedded with angular on IIS server

I am working with Selenium 2 WebDriver. This project is like report automation which automate Some ERP reports. I embedded Python codes batch file with Angular code.
It works fine when I run code on localhost.
But, when I try to run it directly from IIS,
With local system identity then it runs in background.
We unable to see the process, but we received required output.
So what could be the actual problem?

Get terminal logs from remote machine using python

I am executing my Robot Framework Selenium tests in a remote machine (it's a Docker container, but I need it to be working using Podman, too... so I guess using docker commands wouldn't help me) and in this remote machine, there is an automatic process running on the background, which is producing terminal logs.
I can read this cmd output when I execute docker logs <container_id> in my terminal, but I need to get them using python and extract some info from these logs to show them in the Robot Framework test log file.
Any ideas how to do it?
I have found several ways how to execute a command in the remote machine and get the output, but here I am not executing any command, I just need to read what's being produced automatically.
Thank you for your advice

Running python scripts on apache server and get the output as http response

I have a django website hosted on raspberry pi using apache server.
Is there any way I can execute python scripts on the pi server and get the output of the scripts in the website?
I have link to all the python files on the website but when I click them instead of executing the raw code opens.
Aside that this is a very risky thing to do, you can do this in different ways - see these answers, where the second one also shows how to fetch the output:
How can I make one python file run another?
Running shell command from Python and capturing the output

Running Python Server Script program which is in Web site?

I've seen in this link where everytime we will intiate webserver.py script which listens the user request & respond.
In Ubuntu we will usually run in Terminal.Similarly,i would like to know how to run the python file which is in the website.
[EDIT]
Here are links to topics that will help you on your way
Flask/REST/JSON
Sandbox

Categories