参数包含时发生编码错误&

2024-05-14 03:36:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我通过网络表单提交了一个文件名,并让cherrypy接收这个文件名并打开它进行处理。我在这里遇到的问题是,文件何时包含“&“我发现以下错误。 我删除“&;”时没有问题从文件名

文件名:

invoicing - SP30075306 Heidelberg Dust & Dropper.xlsm

Python代码:

reload(sys)  
sys.setdefaultencoding('utf8')

@cherrypy.expose
def cost_breakdown(self, **mate):
    print mate['file'].encode('UTF8')
    offer_path = os.path.join('C:/Users/rihanio/Dropbox/Projects/Python_code/work/gateway/Temp_Project_Files/temp_invoicing', mate['file'].encode('UTF8'))

打印输出错误:

invoicing - SP30075306 Heidelberg Dust

[Errno 2] No such file or directory: u'C:/Users/rihanio/Dropbox/Projects/Python_code/work/gateway/Temp_Project_Files/temp_invoicing\invoicing - SP30075306 Heidelberg Dust '


Tags: path文件名错误sysutf8usersencodefile