I'm running a Flask web service, with text-input, but now I have the problem that the text-input sometimes consists of characters that are not included in the ASCII-character set (Example of error: "(Error: no text provided) 'ascii' codec can't encode character u'\u2019' in position 20)")
My code for the Flask web service looks (somewhat) like this:
class Classname(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser()
self.reqparse.add_argument('text', type=str, required=True, help='Error: no text provided')
super(Classname,self).__init__()
def post(self):
args = self.reqparse.parse_args()
text = args['text']
return resultOfSomeFunction(text)
I already tried to turning the ascii-string into unicode, but that didn't work (error: 'unicode' object is not callable). I also tried to add:
text = re.sub(r'[^\x00-\x7f]',r' ',text)
after the rule
text = args['text']
but that also gave me the same error ('ascii' codec can't encode character).
How can I solve this?