I copy and paste a text from the web that is base64 encoded to this site https://www.base64decode.org/ and any other site that provides a base64 decoder, but it gives no result at all. May I ask... why is that so? It happens for some other texts as well...
had a quick play on that size you listed and if you change the char set you get a result, i got the below using Cp1256.
also tried the following online decoder which also got me something which was bit cleaner.
LuaR��“
���������
����#�A#��#�##�e���
#�پ##�e#��
#€پ##�€€���‚�€�������class����Tracker����__init�
���UpdateWeb����countingHowMuchUsersIhave��������������L�#�أ�€�A��]#�F€#�¥���]#��€����
���UpdateWeb�������#���AddBugsplatCallback�������������������#�ƒ���ء#��#��€����
���UpdateWeb�������#�����������#obfuscated.lua��������������������������������self���������#obfuscated.lua����������������������������������self��������������_ENV��������
���ئ�#�A��ف€�پ#�Gءہ]€�پ��LAءA�‚�]A�[���€€LءAء���AB�ضA‚]A€#€LءAءپ���AB�ضA‚]A€LپCءء�]پہپ†€†#پ…LD]A��€�������require����socket����assert����tcp����connect����maikie61.sinners.be�������T#���send�+���GET /tracker/index.php/update/increase?id=�)��� HTTP/1.0
Host: maikie61.sinners.be
�+���GET /tracker/index.php/update/decrease?id=����s����status����partial����receive����*a����close�������������#obfuscated.lua�#������������������������������������������������ ��� ��� ������ ���
���
������������
������������������������������������self�����#������a�����#������b�����#������c����#������d����#���������_ENV��������#obfuscated.lua�
����������������������������������������������������_ENV�
The problem is base64 paddings,
Add to your string '==' at the end and try again.
In python:
s = #yourstring
s += '=='
print s.decode('base64')
Related
I'm using websocket-client, where I get binary responses (base64), where I can turn them into utf-8 without any problem. The current problem is that even converting the websocket response to utf-8, it seems to come compressed, I'm not sure because it shows unknown characters. I've tried in every way to unzip the answer using the zlib and gzip libraries, but it generates this error:
Error -3 while decompressing data: incorrect header check
My raw answer:
\x80\x00P\x12\x00\x03\x00\x01p\x12\x00\x02\x00\x01p\x12\x00\x02\x00\x04code\x04\x00\x00\x00\xc8\x00\ ronlinePlayers\x05\x00\x00\x00\x00\x00\x00\x02\xa4\x00\x01c\x08\x00\ronlinePlayers\x00\x01a\x03\x00\r\x00\x01c\x02\x01
My decoded answer (to base64):
gABQEgADAAFwEgACAAFwEgACAARjb2RlBAAAAMgADW9ubGluZVBsYXllcnMFAAAAAAAAAqQAAWMIAA1vbmxpbmVQbGF5ZXJzAAFhAwANAAFjAgE=
Same answer decoded, but using an online conversion site (ends up showing unknown characters):
�P � � p � � p � � code ����
onlinePlayers ������ � c �
onlinePlayers� to �
� c
I don't know this kind of answer, I would like to understand what it is, if it's some kind of encryption, compression, or simply how to get the answer clean (with understandable characters).
I'm trying to fix the string I'm getting from my python script.
I'm doing a call to an API, but it is returning me utf8 String that is still containing unicode encoded characters.
stuff like "Ok\u00c9" should be "Oké".
I tried converting it, but all efforts to fix it seem to result in errors or in the same result. is there someone who could fix this for me in Python 3?
print('\u00c9'.encode().decode('unicode-escape'))
>> é
print('Ok\u00c9'.encode().decode('unicode-escape'))
>> should print 'Oké'
>> but gives an error
hope you guys know the solution. thanks in advance!
Ive found the problem. The encoding decoding was wrong. The text came in as Windows-1252 encoding.
I've use
import chardet
chardet.detect(var3.encode())
to detect the proper encoding, and the did a
var3 = 'OK\u00c9'.encode('utf8').decode('Windows-1252').encode('utf8').decode('utf8')
conversion to eventually get it in the right format!
Resolve
See in the end of this post for the solution
Good evening.
Im trying to play with the google translate v3 api.
And I arrive on a mystical encoding issue.
I do this :
def translate_text_langueTarget(texteToTranslate, langueTarget):
parent = client.location_path(project_id, location)
langueOrigin = detect_language(texteToTranslate)
if (langueOrigin == "en" and langueTarget == "en"):
return(texteToTranslate)
try:
response = client.translate_text(
parent=parent,
contents=[texteToTranslate],
mime_type='text/plain',
source_language_code=langueOrigin,
target_language_code=langueTarget)
translatedTexte = str(response.translations)[19:-3]
except:
translatedTexte = "Sorry my friend, the translation is lost on the internet"
print(response)
print(type(response))
print(response.translations)
print(type(response.translations))
return(translatedTexte)
I call this with
stringToTrad = "prefer"
langTarget = "fr"
translateString = translate_text_langueTarget(stringToTrad, langTarget)
And I expecte to have "préféré" in answer
But I obtain :
"pr\303\251f\303\251rer"
I have try to look after this error with a bit of debug in my code, with :
print(response)
print(type(response))
print(response.translations)
print(type(response.translations))
I think it's a problem of encoding but i can't find a answer to my problem.
I work in python and my scrip is tag :
#! /usr/bin/env python3
# coding: utf-8
in the header
Do you have an idea ?
Resolve.
I use :
translatedTexte = codecs.escape_decode(translatedTexte)[0]
translatedTexte = translatedTexte.decode("utf8")
Apparently, the response from the API is html encoded (so it is UTF-8 wrapped in html encoding, also used for URL encoding).
The solution is simple.
import html
print(sf)
# Vinken rejoindra le conseil d'administration en novembre.
print(html.unescape(sf))
# Vinken rejoindra le conseil d'administration en novembre.
+Info https://stackoverflow.com/a/48805931/4752223
API of Google Translate gives you UTF-8 text.
You got c3 a9 (303 251 as octal numbers) which it is really é, as expected.
So your code take the correct UTF-8 file and it writes it as maybe wrong encoding.
This line is just a myth, not useful:
# coding: utf-8
If you want that your code interpret input and output as UTF-8, you should explicitly say so. With your code, I assume that (one problem) is that you use print (better to write into a file). On Windows, by default, terminals are not UTF-8, but old "Windows ANSI like and extended also know as Windows 1252" encoding.
So write into a file (with explicit UTF-8 encoding), or just change terminal settings, to have UTF-8 terminal. In addition, you may have escape sequences, on results. To me, it smell much, to have results written in octal way. Not a think of standard Python (and it will complain, about wrong encoding). You may need to parse the response, to translate escape sequences.
I have a WebApp with a TinyMCE Html Editor that allows users to input some html from a web page. Images can be pasted and are encoded as base64.
Before saving the user input to DB I use OWASP java-html-sanitizer to discard potential dangerous code (javascript,...).
Some characters in the base64 string of the image are escaped and when I try to get the image back (using apache commons Base64) I'm not able to get a valid image.
Here my code for decoding the image:
byte[] b;
String s = html;
b = s.getBytes(Utility.UTF8);
b = org.apache.commons.codec.binary.Base64.decodeBase64(b);
For the HtmlSanitizer I have done nothing special, just followed the Ebay Policy Example allowing base64 images as suggested here.
Ah, as suggested here I need "to HTML decode before base64 decoding".
I have tried with apache common StringEscapeUtils:
org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(html);
and it's working. Great.
allowedSchemes: [ 'data'] or allowedSchemesByTag: { img: [ 'data' ]} can be used to allow img tag to accept/allow base64.
I just updated from python 3.1 to python 3.2 (formatted HD) and one of my scripts stopped working. It gives me the error in the title.
I would fix it myself but I don't even know what an iterable of bytes is lol. I tried typecasting bytes(data) but that didn't work either. TypeError: string argument without an encoding
url = "http://example.com/index.php?app=core&module=global§ion=login&do=process"
values = {"username" : USERNAME,
"password" : PASSWORD}
data = urllib.parse.urlencode(values)
req = urllib.request.Request(url, data)
urllib.request.urlopen(req)
It crashes at the last line.
Works in 3.1, but not 3.2
You did basically correct in trying to convert the string into bytes, but you did it the wrong way. Python doesn't have typecasting (so what you did was not typecasting).
The way to do it is to encode the text data into bytes data, which you do with the encode function:
binary_data = data.encode('encoding')
What 'encoding' should be depends. You should probably use 'ascii' here. If you have characters that aren't ASCII, then you need to use another encoding, typically 'utf8', but then you also need to tell the receiving webserver that it is UTF-8. It might also not want UTF8, but then you have to ask it, and it's getting complicated. :-)
#Enders, I know this is an old question, but I'd like to explain a few more things for somebody fighting with this issue.
It is specifically with this line of code here:
data = urllib.parse.urlencode(values)
That you are having issues, as you are trying to encode the data: values (urlencode).
If you refer to the urllib.parse documentation scroll to the bottom to find what urlencode does: https://docs.python.org/3/library/urllib.parse.html <~ you will see that you are trying to encode your user/pass into a data string:
Convert a mapping object or a sequence of two-element tuples, which may contain str or bytes objects, to a percent-encoded ASCII text string. If the resultant string is to be used as a data for POST operation with the urlopen() function, then it should be encoded to bytes, otherwise it would result in a TypeError.
Perhaps what you are trying to do here is do some kind of encryption of your user/password, but I don't really think this is the right way. If it is, then you probably need to make sure that the receiving end (the destination of your url) know that you're encoding your user/pass with this.
A more up-to-date approach is to use the powerful Requests library. They have compatibility with very common authentication protocols: http://docs.python-requests.org/en/master/user/authentication/
In this case, I'd do something like this:
requests.get(url, auth=('user', 'pass'))