当前位置:网站首页>Premature end of script headers 或 End of script output before headers
Premature end of script headers 或 End of script output before headers
2022-06-29 17:46:00 【孟郎郎】
在测试 Python DB-API 使用流程脚本时,访问出现如下错误:

查看 Apache 日志,错误信息如下:
Premature end of script headers: dblink.py
或者
End of script output before headers: dblink.py
dblink.py 脚本内容如下:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import MySQLdb
# 打开数据库连接
db = MySQLdb.connect("localhost", "数据库用户名", "数据库密码", "数据库", charset='utf8mb4')
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()
print "Database version : %s " % data
# 关闭数据库连接
db.close()通过调试发现,应该是没有标记 HTTP 头部信息结束导致,程序修改如下:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import MySQLdb
# 打开数据库连接
db = MySQLdb.connect("localhost", "数据库用户名", "数据库密码", "数据库", charset='utf8mb4')
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()
print "Content-type:text/html"
print # 空行,告诉服务器结束头部
print "Database version : %s " % data
# 关闭数据库连接
db.close()其中," Content-type:text/html" 为 HTTP 头部的一部分,它会发送给浏览器并告诉浏览器文件的内容类型,用 print 输出一个空行用于告诉服务器结束头部信息。
访问结果如下:
![]()
边栏推荐
- Opencv+YOLO-V3实现目标跟踪
- What is the function of MySQL cursors
- MaxCompute字符串替换函数-replace
- Partial mock of static class of phpunit operation
- R语言将距离矩阵输入给hclust函数进行层次聚类分析,method参数指定两个组合数据点间的距离计算方式、plot函数可视化层次聚类的树状图(dendrogram)
- 分布式 | 几步快速拥有读写分离
- 3H proficient in opencv (IX) - the simplest face detection
- Li Kou today's question -535 Encryption and decryption of tinyurl
- MATLAB 最远点采样(FPS)
- What technology is an applet container? Can it help Internet of things enterprises break through the red sea?
猜你喜欢

SRM供应商协同管理系统功能介绍

小程序容器是什么技术?能助力物联网企业红海突围?
![Split palindrome string [dp + DFS combination]](/img/7b/221b000984977508f849e19802c2c2.png)
Split palindrome string [dp + DFS combination]

基于gis三维可视化的智慧城市行业运用

Matlab farthest point sampling (FPS)

DevCloud加持下的青软,让教育“智”上云端

How to create and delete MySQL triggers

Visio annotation, annotation location

0 basic self-study STM32 (wildfire) - register lit LED

PCB frame drawing - ad19
随机推荐
Younger sister Juan takes you to learn JDBC - 2-day dash Day1
Mac installation php7.2
最受欢迎的30款开源软件
跨境独立站语言unicode转希伯来语
SRM系统可以为企业带来什么价值?
R语言使用MASS包的glm.nb函数建立负二项广义线性模型(negative binomial)、summary函数获取负二项广义线性模型模型汇总统计信息
How to solve the 2003 error of MySQL in Linux
2022 spring summer collection koreano essential reshapes the vitality of fashion
Visio annotation, annotation location
Set double click to run the jar file
What value can SRM systems bring to the enterprise?
阿里云不同账号新旧服务器镜像迁移数据迁移同步
Visio标注、批注位置
Multi mode concurrent implementation of tortoise and rabbit race in go language
Self taught structure (small turtle C language)
SCM系统是什么?供应链管理系统有哪些优势?
Scenario solution for two modules calling each other in go
剑桥大学教授:经常吃早餐害处多,很危险 - 知乎
Distributed | several steps of rapid read / write separation
迈动互联中标大家保险集团