builtins.TypeError: must be str, not bytes

后端 未结 2 1131
不知归路
不知归路 2020-11-27 10:41

I\'ve converted my scripts from Python 2.7 to 3.2, and I have a bug.

# -*- coding: utf-8 -*-
import time
from datetime import date
from lxml import etree
fr         


        
相关标签:
2条回答
  • 2020-11-27 10:55

    Convert binary file to base64 & vice versa. Prove in python 3.5.2

    import base64
    
    read_file = open('/tmp/newgalax.png', 'rb')
    data = read_file.read()
    
    b64 = base64.b64encode(data)
    
    print (b64)
    
    # Save file
    decode_b64 = base64.b64decode(b64)
    out_file = open('/tmp/out_newgalax.png', 'wb')
    out_file.write(decode_b64)
    
    # Test in python 3.5.2
    
    0 讨论(0)
  • 2020-11-27 11:08

    The outfile should be in binary mode.

    outFile = open('output.xml', 'wb')
    
    0 讨论(0)
提交回复
热议问题