Cron jobbin'一个python脚本:停止中途 [英] Cron jobbin' a python script: stops halfway through

查看:191
本文介绍了Cron jobbin'一个python脚本:停止中途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图cronjob我的python脚本。我通过cPanel设置它,我的python脚本生成一个html文件,因此我知道命令是正确的(只是python / path对吗?)



HOWEVER,我生成的html停止中途(在第二个f.write()之后,当我的for循环应该开始)。



当我在本地执行这个脚本时,我没有遇到什么问题,什么给了?

 <$来自SearchPhone import SearchPhone 

phones = [Iphone 3,Iphone 4,Iphone 5,Galaxy s3,Galaxy s2,LG Lucid LG Esteem,HTC One S,Droid 4,
Droid RAZR MAXX,HTC EVO,Galaxy Nexus,LG Optimus 2,LG Ignite,
Galaxy Note,HTC Amaze,HTC Rezound,HTC Vivid,HTC Rhyme,Motorola Photon,
Motorola Milestone,myTouch slide,HTC Status Droid 3,HTC Evo 3d,HTC Wildfire,
LG Optimus 3d,HTC ThunderBolt,Incredible 2,Kyocera Echo,Galaxy S 4g,
HTC Inspire,LG Optimus 2x,Samsung Gem,HTC Evo Shift,Nexus S,LG Axis,Droid 2,
G2,Droid x Droid Incredible
]

f = open('celly.html','w')


f.write(< ;!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> Celly蓝皮书< / title>
< / head>

< body>
< / body>
< / html>


#table
f.write('< table width =100%border =1>')
x in phones:
y = SearchPhone(x)
f.write(\t< tr>)
f.write(\t\t< td>+ str(y [0])+< / td>)
f.write(\t\t< td>+ str(y [1])+< / td> )
f.write(\t\t< td>+ str(y [2])+< / td>)
f.write(\t \t< td>+ str(y [3])+< / td>)
f.write(\t\t< td> )+< / td>)
f.write(\t< / tr>

f.write('< / table>')

f.close()


解决方案


  1. 您的for循环中的最后一行有语法错误:



    f.write(\t<

    您可能没有在生产服务器上的写入权限。
    尝试一次。


f = open('/ tmp / celly.html','w')



如果这个工作,那么它的写权限问题。
检查当前文件夹中
celly.html 文件的权限。应该是可写的。


I'm trying to cronjob my python script. I set it up through cPanel and my python script generates an html file like it's supposed to, so I know the command it correct (just "python /path" right?)

HOWEVER, my generated html stops halfway through (right after the second f.write(), when my for loop should start).

When I execute this script locally, I get no problems, what gives?

from SearchPhone import SearchPhone

phones = ["Iphone 3", "Iphone 4", "Iphone 5","Galaxy s3", "Galaxy s2", "LG Lucid", "LG Esteem", "HTC One S", "Droid 4",
          "Droid RAZR MAXX", "HTC EVO", "Galaxy Nexus", "LG Optimus 2", "LG Ignite",
          "Galaxy Note", "HTC Amaze", "HTC Rezound", "HTC Vivid", "HTC Rhyme", "Motorola Photon",
          "Motorola Milestone", "myTouch slide", "HTC Status", "Droid 3", "HTC Evo 3d", "HTC Wildfire",
          "LG Optimus 3d", "HTC ThunderBolt", "Incredible 2", "Kyocera Echo", "Galaxy S 4g",
          "HTC Inspire", "LG Optimus 2x", "Samsung Gem", "HTC Evo Shift", "Nexus S", "LG Axis", "Droid 2",
          "G2", "Droid x", "Droid Incredible" 
          ]

f = open('celly.html','w')


f.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Celly Blue Book</title>
</head>

<body>
</body>
</html>
""")

#table
f.write('<table width="100%" border="1">')
for x in phones:
    y = SearchPhone(x)
    f.write( "\t<tr>")
    f.write( "\t\t<td>" + str(y[0]) + "</td>")
    f.write( "\t\t<td>" + str(y[1]) + "</td>")
    f.write( "\t\t<td>" + str(y[2]) + "</td>")
    f.write( "\t\t<td>" + str(y[3]) + "</td>")
    f.write( "\t\t<td>" + str(y[4]) + "</td>")
    f.write( "\t</tr>"

f.write('</table>')

f.close()

解决方案

  1. Last line in your for loop has syntax error :

    f.write( "\t</tr>"

  2. You may not have write permissions on your production server . Try this once.

f = open('/tmp/celly.html','w')

if this works, then its a write permission problem. Check permissions of your celly.html file in current folder. It should be writable.

这篇关于Cron jobbin'一个python脚本:停止中途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆