Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
flask app decoding problem
#1
My Problem: My client is sending UTF-16BE encoded strings to flask app server and I am getting as request.args.get('text') when I try to decode
getting garbage.But from the APP server URL I see the correct encoded value and I get prefect output when I use texturlencodedvalue=unquote_plus(unquote_to_bytes("%09%9F%09%BF%09%95%09%BE%00+%06G%06F%06'").decode('utf-16-be'))
My Actual Data is: টিকা هنا
But from Flask after decoding getting: ৯뾽৯뾽৯뾽৯뾽 هنا

###########My Flask APP LOG############
My utf-16-be-decoded output is: ৯뾽৯뾽৯뾽৯뾽 هنا
Actual Decoded output is: টিকা هنا
Output:
192.168.1.60 - - [02/Aug/2021 02:04:33] "GET /?username=test&password=test&to=8801833055942&text=%09%9F%09%BF%09%95%09%BE%00+%06G%06F%06'&from=TestAPI&coding=2&charset=UTF-16BE&smsc=djangolocal&dlr-url=68c0b864-5029-490f-b92a-62b27ab5b5dc&dlr-mask=19 HTTP/1.1" 0 -
My Environment Details:
########################
Output:
OS: CentOS 8 Locale : 'UTF-8' Python Version : Python 3.6.8 Flask 2.0.1 Werkzeug 2.0.1
################# My Flask Application###########
from flask import Response
import requests
from requests.structures import CaseInsensitiveDict
import vonage
from vonage import Client
from urllib.parse import unquote,quote, unquote_to_bytes,unquote_plus,parse_qs,parse_qsl
import urllib.parse
import sys


app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
@app.route('/')
def index():
    username=request.args.get('username')
    password=request.args.get('password')
    to=request.args.get('to')
    sender=request.args.get('from')
    text=unquote_plus(unquote_to_bytes(request.args.get('text')).decode('utf-16-be'))
    coding=request.args.get('coding')
    charset=request.args.get('charset')
    binfo=request.args.get('binfo')
    account=request.args.get('account')
    smsc=request.args.get('smsc')
    dlr_url=request.args.get('dlr-url')
    dlr_mask=request.args.get('dlr-mask')
    print("My utf-16-be-decoded output is: " +text)
    texturlencodedvalue=unquote_plus(unquote_to_bytes("%09%9F%09%BF%09%95%09%BE%00+%06G%06F%06'").decode('utf-16-be'))
    print("Actual Decoded output is: "+texturlencodedvalue)
    try:
        if str(to):
                    client = vonage.Client(key="Test", secret="Test")
                    sms = vonage.Sms(client)
                    if coding==0 or coding==0:
                       responseData = sms.send_message({"from": "Vonage APIs","to": to,"text": text,'type': 'unicode',})
                    else:
                       responseData = sms.send_message({"from": "Vonage APIs","to": to,"text": text,'type': 'unicode',})

                    if responseData["messages"][0]["status"] == "0":
                       print("Message sent successfully.")
                       return Response(status="ok")
                    else:
                        print(f"Message failed with error: {responseData['messages'][0]['error-text']}")
                        return Response(status="failure")
    except Exception as e:
        print(str(e))
        return Response(status="retry later")

if __name__ == '__main__':
    app.run(debug=True, port=5000,host='0.0.0.0')
Larz60+ write Aug-02-2021, 09:10 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
fixed for you this time. Please use bbcode tags on future posts.
Reply


Messages In This Thread
flask app decoding problem - by mesbah - Aug-01-2021, 08:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decoding lat/long in file name johnmcd 4 349 Mar-22-2024, 11:51 AM
Last Post: johnmcd
  Problem with flask on Mac David763 13 2,396 Dec-19-2023, 07:22 PM
Last Post: David763
  Enigma Decoding Problem krisarmstrong 4 722 Dec-14-2023, 10:42 AM
Last Post: Larz60+
  json decoding error deneme2 10 3,621 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  Decoding a serial stream AKGentile1963 7 8,521 Mar-20-2021, 08:07 PM
Last Post: deanhystad
  Problem with Flask Bcrypt import module marcello86 2 5,699 Aug-31-2020, 08:10 PM
Last Post: marcello86
  xml decoding failure(bs4) roughstroke 1 2,253 May-09-2020, 04:37 PM
Last Post: snippsat
  python3 decoding problem but python2 OK mesbah 0 1,802 Nov-30-2019, 04:42 PM
Last Post: mesbah
  utf-8 decoding failed every time i try adnanahsan 21 10,826 Aug-27-2019, 04:25 PM
Last Post: adnanahsan
  hex decoding in Python 3 rdirksen 2 4,596 May-12-2019, 11:49 AM
Last Post: rdirksen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020