How to base64 encode a html_string
up vote
0
down vote
favorite
AIM
I am attempting to encode a folium
choropleth as StringIO
. I am basing my answer of a related query. I have checked the answers here and here.
ERROR
AttributeError: 'bytes' object has no attribute 'encode'
CODE
views.py
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
f = StringIO(html_string)
choropleth = base64.b64decode(f.read())
choropleth = choropleth.encode('utf8') # causing error
return {'choropleth':choropleth}
python django base64 stringio
add a comment |
up vote
0
down vote
favorite
AIM
I am attempting to encode a folium
choropleth as StringIO
. I am basing my answer of a related query. I have checked the answers here and here.
ERROR
AttributeError: 'bytes' object has no attribute 'encode'
CODE
views.py
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
f = StringIO(html_string)
choropleth = base64.b64decode(f.read())
choropleth = choropleth.encode('utf8') # causing error
return {'choropleth':choropleth}
python django base64 stringio
1
simply try to replacechoropleth.encode('utf8')
bychoropleth.decode('utf8')
and please refer to the documentation
– Chiheb Nexus
Nov 11 at 1:25
1
wellb'xe0'.decode('latin')
will output'à'
. So, maybe your string isn't reallyutf8
compliant.
– Chiheb Nexus
Nov 11 at 3:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
AIM
I am attempting to encode a folium
choropleth as StringIO
. I am basing my answer of a related query. I have checked the answers here and here.
ERROR
AttributeError: 'bytes' object has no attribute 'encode'
CODE
views.py
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
f = StringIO(html_string)
choropleth = base64.b64decode(f.read())
choropleth = choropleth.encode('utf8') # causing error
return {'choropleth':choropleth}
python django base64 stringio
AIM
I am attempting to encode a folium
choropleth as StringIO
. I am basing my answer of a related query. I have checked the answers here and here.
ERROR
AttributeError: 'bytes' object has no attribute 'encode'
CODE
views.py
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
f = StringIO(html_string)
choropleth = base64.b64decode(f.read())
choropleth = choropleth.encode('utf8') # causing error
return {'choropleth':choropleth}
python django base64 stringio
python django base64 stringio
edited Nov 13 at 3:26
asked Nov 11 at 1:13
ycrad
928
928
1
simply try to replacechoropleth.encode('utf8')
bychoropleth.decode('utf8')
and please refer to the documentation
– Chiheb Nexus
Nov 11 at 1:25
1
wellb'xe0'.decode('latin')
will output'à'
. So, maybe your string isn't reallyutf8
compliant.
– Chiheb Nexus
Nov 11 at 3:32
add a comment |
1
simply try to replacechoropleth.encode('utf8')
bychoropleth.decode('utf8')
and please refer to the documentation
– Chiheb Nexus
Nov 11 at 1:25
1
wellb'xe0'.decode('latin')
will output'à'
. So, maybe your string isn't reallyutf8
compliant.
– Chiheb Nexus
Nov 11 at 3:32
1
1
simply try to replace
choropleth.encode('utf8')
by choropleth.decode('utf8')
and please refer to the documentation– Chiheb Nexus
Nov 11 at 1:25
simply try to replace
choropleth.encode('utf8')
by choropleth.decode('utf8')
and please refer to the documentation– Chiheb Nexus
Nov 11 at 1:25
1
1
well
b'xe0'.decode('latin')
will output 'à'
. So, maybe your string isn't really utf8
compliant.– Chiheb Nexus
Nov 11 at 3:32
well
b'xe0'.decode('latin')
will output 'à'
. So, maybe your string isn't really utf8
compliant.– Chiheb Nexus
Nov 11 at 3:32
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
After some trial-and-error, the following worked for me:
SOLUTION
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
encoded_bytes = html_string.encode('utf-8')
encoded_bytes = base64.b64encode(encoded_bytes)
encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode
choropleth = encoded_bytes
return {'choropleth':choropleth}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
After some trial-and-error, the following worked for me:
SOLUTION
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
encoded_bytes = html_string.encode('utf-8')
encoded_bytes = base64.b64encode(encoded_bytes)
encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode
choropleth = encoded_bytes
return {'choropleth':choropleth}
add a comment |
up vote
0
down vote
accepted
After some trial-and-error, the following worked for me:
SOLUTION
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
encoded_bytes = html_string.encode('utf-8')
encoded_bytes = base64.b64encode(encoded_bytes)
encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode
choropleth = encoded_bytes
return {'choropleth':choropleth}
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
After some trial-and-error, the following worked for me:
SOLUTION
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
encoded_bytes = html_string.encode('utf-8')
encoded_bytes = base64.b64encode(encoded_bytes)
encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode
choropleth = encoded_bytes
return {'choropleth':choropleth}
After some trial-and-error, the following worked for me:
SOLUTION
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
encoded_bytes = html_string.encode('utf-8')
encoded_bytes = base64.b64encode(encoded_bytes)
encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode
choropleth = encoded_bytes
return {'choropleth':choropleth}
answered Nov 11 at 4:08
ycrad
928
928
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244984%2fhow-to-base64-encode-a-html-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
simply try to replace
choropleth.encode('utf8')
bychoropleth.decode('utf8')
and please refer to the documentation– Chiheb Nexus
Nov 11 at 1:25
1
well
b'xe0'.decode('latin')
will output'à'
. So, maybe your string isn't reallyutf8
compliant.– Chiheb Nexus
Nov 11 at 3:32