问题记录2:TypeError: write() argument must be str, not bytes
今天试了下用requests模块的get()方法来下载图片,写入文件的时候不能写入二进制,然后将打开方式改成二进制的就好了。
原因是,f.content的存储方式是二进制,而文件正常打开默认是字符串的形式,所以如果写入的是二进制,那么打开文件的时候也需要以二进制的形式打开。

问题记录2:TypeError: write() argument must be str, not bytes的更多相关文章
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
今天写上传文件代码,如下 def uploadHandle(request): pic1=request.FILES['pic1'] picName=os.path.join(settings.MED ...
- Python错误TypeError: write() argument must be str, not bytes
2016-07-03 20:51:25 今天使用Python中的pickle存储的时候出现了以下错误: TypeError: write() argument must be str, not byt ...
- TypeError: write() argument must be str, not bytes报错
TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...
- TypeError: write() argument must be str, not bytes报错原因及Python3写入二进制文件方法
Python2随机写入二进制文件: with open('/python2/random.bin','w') as f: f.write(os.urandom(10)) 但使用Python3会报错: ...
- TypeError: write() argument must be str, not bytes
w文件打开以 '二进制' 方式: with open('teacher.html','wb+') as f: f.write(response.body) 要写入"中文",防止乱 ...
- python write() argument must be str, not bytes
python pickle from __future__ import absolute_import from __future__ import division from __future__ ...
- Python - TypeError: unicode argument expected, got 'str'
参考:TypeError: unicode argument expected, got 'str' Python代码: from io import StringIO def main(): f = ...
- Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'
python3往这个库中加入了一些新的内容,使得该库在Python2.7中报错. 解决方法是将导入语句 from io import StringIO as StringIO 更换为: from io ...
- statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'
在 python 中用 statsmodels创建 ARIMA 模型进行预测时间序列: import pandas as pd import statsmodels.api as sm df = pd ...
随机推荐
- [推荐分享]大量Javascript/JQuery学习教程电子书合集,送给有需要的人
不收藏是你的错^_^. 经证实,均可免费下载. 资源名称 资源大小 15天学会jQuery(完整版).pdf 274.79 KB 21天学通JavaScript(第2版)-顾宁燕扫描版.pdf ...
- python chanllenge题解
网址:chanllenge 修改url最后的html的前缀为答案,就可以过关. 页面上很多只有一幅图片,实际上题目描述全在页面源码中. 然后推荐一个在线代码运行的网站 ideone 查看所有源码:ht ...
- Linq无聊练习系列3--聚合函数练习
/**************聚合函数 练习*******************/ //求学生的总数量 var list = ctx.T_Student. ...
- Hadoop作业提交之TaskTracker获取Task
[Hadoop代码笔记]Hadoop作业提交之TaskTracker获取Task 一.概要描述 在上上一篇博文和上一篇博文中分别描述了jobTracker和其服务(功能)模块初始化完成后,接收JobC ...
- Java泛型学习笔记--Java泛型和C#泛型比较学习(一)
总结Java的泛型前,先简单的介绍下C#的泛型,通过对比,比较学习Java泛型的目的和设计意图.C#泛型是C#语言2.0和通用语言运行时(CLR)同时支持的一个特性(这一点是导致C#泛型和Java泛型 ...
- Xcode开发和调试总结
Xcode是iOS开发主要的工具.IDE.关于Xcode的细枝末节,可以参考苹果的官方文档或者众多的说明.此文档主要涉及常用开发和调试注意事项,参考版本为Xcode 5.1.1. 目标设置: 在此,我 ...
- 基于.NET打造IP智能网络视频监控系统
开源倾情奉献:基于.NET打造IP智能网络视频监控系统(一)开放源代码 开源倾情奉献系列链接 开源倾情奉献:基于.NET打造IP智能网络视频监控系统(一)开放源代码 开源倾情奉献:基于.NET打造 ...
- sublime text 3 插件:package control
sublime text 3安装package control import urllib.request,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf ...
- js漫谈
不久前在武汉这边找到了自己的第一份软件方面工作,当时还很欢喜,可惜最后因为家里的事情,公司的情况等等,最近又成了待业状态,正好安静的考虑一下以后怎么走,是考研还是继续找工作,非计算机专业学生自学找软件 ...
- reading words in your computer and changing to female voice, linux festival text2wave saving wav files
on a brand new linux PC, e.g. ubuntu 14.04 amd64 To hear voice sudo apt-get install festival -y then ...