[Python] How can I decode arabic and urdu characters python

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to convert a string in base64 into actual readable characters but some of the text contains characters in the urdu and arabic languages such as:

    \\xd8\\xb9\\xdb\\x81\\xd8\\xaf\\xd9\\x90 \\xd9\\x86\\xd9\\x88\r\n\\xd8\\xa2\\xd9\\x8f\\xd8\\xb1\\xd8\\xaf\\xd9\\x88 \\xd8\\xaa\\xd8\\xaf\\xd8\\xb1\\xdb\\x8c\\xd8\\xb3 \\xd9\\x85\\xdb\\x8c\\xda\\xba \\xd8\\xa8\\xdb\\x81\\xd8\\xaa\\xd8\\xb1\\xdb\\x8c \\xda\\xa9\\xdb\\x92 \\xd9\\x84\\xdb\\x8c\\xdb\\x92 \\xd8\\xa7\\xdb\\x81\\xd8\\xaf\\xd8\\xa7\\xd9\\x81


    when I remove the extra backslashes and put it in the terminal I get

    Ø¹ÛØ¯ÙÙØ¢ÙØ±Ø¯Ù ØªØ¯Ø±ÛØ³ Ù
    ÛÚº Ø¨ÛØªØ±Û Ú©Û Ù
    ÛÛ Ø§ÛØ¯Ø§Ù


    How can I convert the above string correctly?

    Edit:

    I got this string from an email using the gmail API. This is the string of the email:

    DQpIaSBNT0hBTU1BRCwNCllvdXIgd29yayDYuduB2K_ZkCDZhtmIICANCjxodHRwczovL2NsYXNzcm9vbS5nb29nbGUuY29tL2MvTWpJek5UVXhNekl5T1RFMS9hL01qTTBPRE14TURrNE9EUXcvc3VibWlzc2lvbnM-ICANCmlzIGR1ZSB0b21vcnJvdy4gV291bGQgeW91IGxpa2UgdG8gdHVybiBpdCBpbj8NCg0K2Lnbgdiv2ZAg2YbZiA0KRHVlOiBKYW4gMjQNCk9QRU4gIA0KPGh0dHBzOi8vY2xhc3Nyb29tLmdvb2dsZS5jb20vYy9Nakl6TlRVeE16SXlPVEUxL2EvTWpNME9ETXhNRGs0T0RRdy9zdWJtaXNzaW9ucz4NCklmIHlvdSBkb24ndCB3YW50IHRvIHJlY2VpdmUgZW1haWxzIGZyb20gQ2xhc3Nyb29tLCB5b3UgY2FuIHVuc3Vic2NyaWJlICANCjxodHRwczovL2NsYXNzcm9vbS5nb29nbGUuY29tL3M-Lg0KDQpHb29nbGUgTExDDQoxNjAwIEFtcGhpdGhlYXRyZSBQa3d5DQpNb3VudGFpbiBWaWV3LCBDQSA5NDA0MyBVU0ENCg==


    To decode it you run it through base64.urlsafe_b64decode. In this string there will be unicode characters like those which were listed above. How do I decode those into the urdu and arabic characters?

    Continue reading...

Compartilhe esta Página