signal仅在主线程中有效,未声明编码

时间:2018-01-19 00:30:03

标签: python flask

当我激活DEBUG模式时,我收到以下编码错误:     set FLASK_DEBUG=1 出于某种原因,调试模式不会被app.debug=True激活。这是错误:

Non-UTF-8 code starting with '\x90' in file 
C:\Users\mypc\Anaconda3\envs\fenv\Scrip
ts\flask.exe on line 1, but no encoding declared; see 
http://python.org/dev/peps/pep-0263/ for de
tails

我在此链接中尝试了解决方案,但它没有帮助! Working with utf-8 encoding in Python source

然后我尝试了以下命令:     python -m flask run 我收到以下错误:

handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

这是我的代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, url_for, request, render_template, jsonify
import requests, json
from urllib.request import quote
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 
'postgresql://postgres:password@localhost/flask'
db = SQLAlchemy(app)


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)

def __init__(self, username, email):
    self.username = username
    self.email = email

def __repr__(self):
    return '<User %r>' % self.username
@app.route('/')
def Index():
    return render_template('add_user.html')

@app.route('/postuser', methods=['POST'])
def post_user():
    user = User(request.form['username'], request.form['email'])
    db.session.add(user)
    db.session.commit()

0 个答案:

没有答案