当前位置:网站首页>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 输出一个空行用于告诉服务器结束头部信息。
访问结果如下:
![]()
边栏推荐
- 布隆过滤器:
- Top 30 open source software
- 软件快速交付真的需要以安全为代价吗?
- 上班可以做副业
- Mongotemplate - distinct use
- 基于STM32F103ZET6库函数独立看门狗(IWDG)实验
- 自定義HandlerInterceptor攔截器實現用戶鑒權
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
- The R language inputs the distance matrix to the hclust function for hierarchical clustering analysis. The method parameter specifies the distance calculation method between two combined data points,
- VB. Net read / write NFC ntag tag source code
猜你喜欢

YoloV6+TensorRT+ONNX:基于WIN10+TensorRT8+YoloV6+ONNX的部署

sequential detector

How MySQL queries character set codes of tables

Prevent form resubmission based on annotations and interceptors

Professor of Cambridge University: eating breakfast often is harmful and dangerous. - you know what
![Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]](/img/33/bda0a898bfe3503197026d1f62e851.png)
Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]

What are the usage scenarios for locks in MySQL

双亲委派机制

人脸识别4-百度商用方案调研

关于日期相加减问题
随机推荐
The aggregate function in the epidisplay package of R language divides numerical variables into different subsets based on factor variables, and calculates the summary statistics and aggregate data. W
人脸识别4-百度商用方案调研
VB. Net read / write NFC ntag tag source code
Split palindrome string [dp + DFS combination]
Self taught structure (small turtle C language)
[the sixth operation of modern signal processing]
从一个被应用商店坑了的BUG说起
Visual Studio插件CodeRush正式发布v22.1——优化调试可视化工具
Li Kou today's question -535 Encryption and decryption of tinyurl
3H proficient in opencv (IX) - the simplest face detection
SRM系统可以为企业带来什么价值?
填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]
一次采集JSON解析错误的修复
On adding and subtracting dates
Younger sister Juan takes you to learn JDBC - 2-day dash Day1
R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses exp function and coef function to ob
分割回文串[dp + dfs组合]
R language uses GLM of mass package The Nb function establishes the negative binomial generalized linear model, and the summary function obtains the summary statistical information of the negative bin
R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
selenium 组合键操作