正常执行期间的Python脚本错误,但在调试期间不会

时间:2015-04-13 21:11:45

标签: python xhtml2pdf

我有一个python 2.7脚本,它使用xhtml2pdf库从.html导出到.pdf

当我从IDLE或Visual Studio 2013运行脚本时,脚本运行正常。但是当我尝试从dos窗口或计划任务执行它时,我收到错误:

'ascii' codec can't decode byte 0xa0 in position 6: ordinal not in range(128)

产生错误的代码行是:

                import xhtml2pdf.pisa as pisa
                pdf = pisa.CreatePDF(
                    file( TargetFileDest + "\\" + target_file + ".html", "r"),
                    file( TargetFileDest + "\\" + target_file + ".pdf", "wb"),
                    log_warn = 1,
                    log_err = 1,
                    path = os.path.join(os.getcwd(),  TargetFileDest + "\\" + target_file + ".html")
                    )

该错误似乎是一个unicode问题,但如果我无法在调试模式下发生错误,我不知道如何调试它。任何建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

我之前见过这个。发生的事情是IDLE和VS都使用不同的字符集(我认为是UTF-8)而不是使用ASCII的命令行。

在命令行中启动python程序之前尝试运行chcp 65001,看看是否有效。

相关问题