'Server won't run this part of Python code
We have a server for python scripts, where there is quite a lot of them running already, but for some reason one code won't run and it is because of this part:
def getData(ico):
url = "https://www.mojedatovaschranka.cz/sds/ws/call"
headers = {'Content-Type':'application/xml'}
data = """
<GetInfoRequest xmlns="http://seznam.gov.cz/ovm/ws/v1">
<Ico>{}</Ico>
</GetInfoRequest>
""".format(ico)
response = requests.post(url, headers=headers, data=data)
#print(response.status_code)
#print(response.text)
data = xmltodict.parse(response.content)
#print(data)
return data
for It is offical api for some data off all legal subjects, not really important. We cant figure out, what is wrong with this segment.
There are other codes with API calls, so there is not a problem, thant server can't send them.
Also we have newest python 7.3.1 installed.
All libs are installed and used by other scripts.
This is the only message we got: Task Scheduler successfully completed task "\Python\API_Databox" , instance "{0b448401-dedd-4cbc-9200-8addd409dfcf}" , action "C:\Windows\SYSTEM32\cmd.exe" with return code 2147942401.
Also it runs normally on my computers.
So my question is, does somebody know what might fix the issue or why server cant"t run this specific code? Other similar codes are running just fine.
Solution 1:[1]
Maybe it's a long shot but I had that exact error message when trying to execute a simple .bat file with task scheduler as another user....
The script called an .exe with some options.
It started fine manually, but the task failed and failed. After playing around with the program, arguments, and start in fields in task scheduler I moved the .bat to the other documents folder of the user I was trying to run the task with. Tried to run it with a cmd launched as that account. Guess what, it couldn't find the exe...
In the end I realized that task scheduler and the other account had no idea where the .exe was located. Copied it over to where the script was and it finally ran correctly. Hope this helps ;)
Solution 2:[2]
Try testing from the context of the running task, rather than the logged in user. You could write the output of what your getData function returns, or the resulting exception, to a text file like this:
try:
x = getData("valid input data for website")
with open('py_log.txt', 'w') as f:
f.write("Function ran without exception, it returned:\n")
f.write(str(x))
except Exception as e:
with open('py_log.txt', 'w') as f:
if 'x' in globals():
f.write("Function threw an exception, it returned\n")
f.write(str(x))
f.write("Reported exception\n")
f.write(str(e))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | def 1nity |
| Solution 2 |
