我正在尝试运行pyhton。在apache wamp服务器上。代码的HTML端工作正常,但当它转到python脚本时。我得到以下错误:
脚本‘test.py’中格式错误的标题:糟糕的标题:
FISCAL_WEEK_NUMBER .,推荐者:http://localhost/test.html
我试着在IDE上分别测试我的python代码,它运行得很好。我在这里找不到这个问题。下面是我的代码:
#!C:/Program Files (x86)/Python36-32/python.exe
import cgi
import os
import cgitb;
import pandas as pd
import teradata
import numpy as np
os.environ["USERNAME"] = "hjoshi"
form = cgi.FieldStorage()
# Get filename here.
fileitem = form['filename']
# Test if the file was uploaded
if fileitem.file:
fn = os.path.basename(fileitem.filename)
query = "insert into p_piw_stg.sales_goals_test_harsh (?, ?, ?, ?)" #insert query for database
input = pd.read_excel('C:/Users/hjoshi/Downloads/' + fn)
test = pd.DataFrame(input, columns = ["FISCAL_WEEK_NUMBER", 'STORE_NUMBER', 'DEPARTMENT', 'SALES_GOAL_AMOUNT']) #creating a dataframe
#print(test)
num_of_chunks = len(test)
host,username,password = 'someIP','elt_usr', 'elt_usr'
udaExec = teradata.UdaExec(appName="test", version="1.0", logConsole=False)
with udaExec.connect (method="odbc",system=host, username=username, password=password, driver="Teradata") as con:
chunks = np.array_split(test, num_of_chunks)
for i,row in enumerate(chunks):
print(row)
data = [tuple(x) for x in chunks[i].to_records(index=False)]
con.executemany(query, data, batch=True)
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
print ("""
Content-Type: text/html\n\r\n
<html>
<body>
<p>%s</p>
</body>
</html>
""" % (message,))发布于 2019-12-12 17:35:34
通过编写代码,我找到了解决上述问题的方法
print("Content-Type: text/html\n\r\n")写完进口后的右上角。代码无法识别应该放在第一位的html头。
https://stackoverflow.com/questions/59309025
复制相似问题