อยากทราบวิธีการแก้ปัญหาอะครับ
ผมจะทำการเรียกฐานข้อมูลมาแสดงแต่ติด
โค้ด เรียกตารางUnicodeDecodeError
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
โค้ด: เลือกทั้งหมด
# -*- coding=utf-8 -*-
from __future__ import unicode_literals
from flask import Flask, current_app, g
from flask import render_template
import psycopg2 as p
import click
click.disable_unicode_literals_warning = True
app = Flask(__name__)
app.config.from_pyfile('app.cfg')
con = p.connect(database='miniproject', user='openpg', password='openpgpwd')
cur = con.cursor()
@app.route('/show2') #กำหนด หน้า path
def show(): #def เป็นคำสำคัญสำหรับการสร้างฟังก์ชัน
sql = "SELECT * FROM genpdf ORDER BY fileid"
sql = sql.encode('utf-8')
cur.execute(sql)
rows = cur.fetchall() # ทำการเลือกข้อมูลทั้งหมด
return render_template('show2.html', rows=rows)
app.run(debug=True)
โค้ด: เลือกทั้งหมด
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>แสดงข้อมูล</title>
</head>
<script>
function confirm_delete() {
return confirm("คุณต้องการที่จะลบข้อมูลใช่หรอไม่");
}
</script>
<body>
<!-- สร้างตารางเพื่อทำการแสดงข้อมูล-->
<div class = "container">
<div ></div>
<div>
<table class="table table-bordered" border="1" cellspacing="5" width="80%" height="5" align="center">
<a href = "/">กลับหน้าหลัก</a>
<br>
<thead>
<!-- สร้าง ส่วนหัวขอตาราง -->
<td align="center">ID</td>
<td align="center">ชื่อไฟล์</td>
<td align="center">คำอธิบาย</td>
<td align="center">เวลา</td>
<td align="center">IP</td>
<td colspan="2" align="center" width="10%">เครื่องมือ</td>
</thead>
<!-- วนลูปเพื่อดึงข้อมูลมาแสดง -->
{% for row in rows %}
<tr>
<td align="center">{{ row[0] }}</td>
<td align="center">{{ row[1] }}</td>
<td align="center">{{ row[2] }}</td>
<td align="center">{{ row[3] }}</td>
<td align="center">{{ row[4] }}</td>
</tr>
{% endfor %} <!-- ปิดลูป-->
</table>
</div><div ></div></div></body>
</body>
</html>
ข้อมูลตารงฐานข้อมูลUnicodeDecodeError
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
กระทู้ที่มีปัญหาคล้ายกัน แต่ยังไม่มีข้อสรุป
viewtopic.php?f=16&t=57105
viewtopic.php?f=16&t=50214