1

I get the following error for encoding when I activate DEBUG mode: set FLASK_DEBUG=1 For some reason, the debug mode does not get activated by app.debug=True. Here is the error:

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

I tried the solution in the this link but it didn't help! Working with utf-8 encoding in Python source

Then I tried the following command: python -m flask run And I got the following error:

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

This is my code :

#!/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()
Ehsan
  • 21
  • 6
  • what was the error after you added `# -*- coding: utf-8 -*-`? – gidim Jan 19 '18 at 00:46
  • Same error `SyntaxError: 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` – Ehsan Jan 19 '18 at 00:57
  • @ehsan did you ever find a solution to this? I've seen your other question as well, no answers..https://stackoverflow.com/questions/48225473/how-to-use-signal-in-thread – Jed Dec 15 '18 at 17:39

0 Answers0