Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python script running through php (cli and mod-php differences)

here some difficulties with running python script through apache mod-php

fname='/tmp/catalog.xml'
http=urllib3.PoolManager()
response=http.request('GET','https://xxxx/xxxxx.xml')
doc=response.data.decode('UTF-8')
print('Saving xml...')
with open(fname,'w') as catalog:
    catalog.write(doc)
print('Parsing...')

this code executed from php script and perfectly works when i execute it from cli like that : sudo -u www-data php -f test.php , in the tmp directory appears file catalog.xml with data in it. but when i execute same php script though web browser, the result from executing just string "Saving xml...", and empty file catalog.xml in the tmp directory. somehow data did not written in the file, but it creates

all permissoins are correct, file creates but it is empty, there is no errors at all in the php log file

like image 911
user3212640 Avatar asked Jun 07 '26 11:06

user3212640


1 Answers

problem solved. it was encoding problem. very strange that it works great in the cli and won't in mod-php. i just add encoding='utf-8'

fname='/tmp/catalog.xml'
http=urllib3.PoolManager()
response=http.request('GET','https://xxxx/xxxxx.xml')
doc=response.data.decode('UTF-8')
print('Saving xml...')
with open(fname,'w',encoding='utf-8') as catalog:
    catalog.write(doc)
print('Parsing...')

and it works!

like image 173
user3212640 Avatar answered Jun 10 '26 03:06

user3212640



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!