PythonAnywhere Forums

Scheduled task behaves different then when run in console

I have a task that fills(Ideally) my database with fresh data every day from the web. I have successfully been running the script from Files (normal console), but when i schedule it it crashes. Are there any restrictions for scheduled task (Firewalls etc.)?


This is my call: /usr/bin/python2.7 -i /home/imlercj/Beta/FillDB.py


This is my error:


0 https://www.yr.no�/�s�t�e�d�/�N�o�r�g�e�/���s�t�f�o�l�d�/�H�a�l�d�e�n�/�B�e�r�g�_�k�i�r�k�e�/� �varsel_time_for_time.xml Traceback (most recent call last): File "/home/imlercj/Beta/FillDB.py", line 39, in <module> forcast = Yr(tmp[i][3],i) File "/home/imlercj/Beta/Yr.py", line 31, in Yr data = xmltodict.parse(response) File "/home/imlercj/.local/lib/python2.7/site-packages/xmltodict.py", line 328, in parse parser.ParseFile(xml_input) xml.parsers.expat.ExpatError: mismatched tag: line 7, column 2


How can this be debuged when it runns perfectly in the normal console?

You're parsing a response and it's failing. Dump the response to a file so you can see why the parsing is failing.

It seems like it is a problem with utf-8 encoding of the string. It does not request the right address and don't get the right answer. But this worked fine in the regular console. How come it is different now that it is run as a scheduled task?

Something about your code is dependent on something in the environment that is different. You know one thing that is different so work back from that until you find the original difference.

I am running the code now on the online console (Files-->/home/imlercj/Beta/FillDB.py) and it works fine. The problem only occurs when i try to start it as a scheduled task. Are there more ways to start a Task ? I tried the 'touch' ,like when you restart a Web App, with success.

No, scheduled tasks run on a schedule, so that's how they are started.

*Fixed it:*

Scheduled task:

bash /home/imlercj/Beta/bash.sh


bash.sh:

#!/bin/bash. echo "hei"

cd ..

cd ..

cd ..

ls

python2.7 /home/imlercj/Beta/FillDB.py

echo "done"