错误内容:UnicodeEncodeError: 'ascii' codec can't encode characters in position 28-29: ordinal not in range(128)

1.以为是代码错误,检查tab符,并没有问题,

2.将代码粘贴到空白项目中去,发现还是不对。

3.百度:http://blog.csdn.net/olanlanxiari/article/details/48201231

  1.Python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128),python没办法处理非ascii编码的,此时需要自己设置将python的默认编码,一般设置为utf8的编码格式。

  2.将上面问题自身检查,我这不存在这种问题,所以继续百度

  3.发现python3 urlopen()链接地址不能出现中文,,那么有中文怎么办?

    a.办法总是有的:替换

    b.将中文内容通过quote方法替换

       from urllib.parse import quote

       quote(url)

       quote(url,safe='/:?=')  

    c.quote可用的参数如下:

      quote(string,safe='/',encoding=None,errors=None)

      reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ","

  

python3 urllib.request.urlopen() 地址打开错误的更多相关文章

  1. (转)python3 urllib.request.urlopen() 错误UnicodeEncodeError: 'ascii' codec can't encode characters

    代码内容: url = 'https://movie.douban.com/j/search_subjects?type=movie'+ str(tag) + '&sort=recommend ...

  2. Python3 urllib.request库的基本使用

    Python3 urllib.request库的基本使用 所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地. 在Python中有很多库可以用来抓取网页,我们先学习urlli ...

  3. urllib.request.urlopen(req).read().decode解析http报文报“utf-8 codec can not decode”错处理

    老猿前期执行如下代码时报"'utf-8' codec can't decode byte"错,代码及错误信息如下: >>> import urllib.reque ...

  4. 爬虫小探-Python3 urllib.request获取页面数据

    使用Python3 urllib.request中的Requests()和urlopen()方法获取页面源码,并用re正则进行正则匹配查找需要的数据. #forex.py#coding:utf-8 ' ...

  5. 【转】python3 urllib.request 网络请求操作

    python3 urllib.request 网络请求操作 基本的网络请求示例 ''' Created on 2014年4月22日 @author: dev.keke@gmail.com ''' im ...

  6. python3 urllib.request 网络请求操作

    python3 urllib.request 网络请求操作 基本的网络请求示例 ''' Created on 2014年4月22日 @author: dev.keke@gmail.com ''' im ...

  7. python之urllib.request.urlopen(url)报错urllib.error.HTTPError: HTTP Error 403: Forbidden处理及引申浏览器User Agent处理

    最近在跟着院内大神学习python的过程中,发现使用urllib.request.urlopen(url)请求服务器是报错: 在园子里找原因,发现原因为: 只会收到一个单纯的对于该页面访问的请求,但是 ...

  8. 关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法

    #encoding:UTF-8 import urllib.request url = "http://www.baidu.com" data = urllib.request.u ...

  9. 在python3中使用urllib.request编写简单的网络爬虫

    转自:http://www.cnblogs.com/ArsenalfanInECNU/p/4780883.html Python官方提供了用于编写网络爬虫的包 urllib.request, 我们主要 ...

随机推荐

  1. [React] Extracting Private React Components

    we leverage private components to break our render function into more manageable pieces without leak ...

  2. Adobe/Flash Media Server 5.0 linux 64位系统下的安装

    一.下载 Adobe/Flash MS5.0下载地址: http://fs1.d-h.st/download/00036/VOt/adobemediaserver_5_ls1_linux64.tar. ...

  3. 自定义PopupWindow动画效果

    public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...

  4. Python 日期和时间(转)

    Python 日期和时间 Python程序能用很多方式处理日期和时间.转换日期格式是一个常见的例行琐事.Python有一个 time 和 calendar 模组可以帮忙. 什么是Tick? 时间间隔是 ...

  5. MacOS U盘安装

    通过Mac上的App Store下载安装程序 插入U盘 启动终端 输入命令  sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/R ...

  6. IFeatureClass.Search中的 Recycling 参数 - 浅谈.

    语法: public IFeatureCursor Search ( IQueryFilter filter, bool Recycling); 当 Recycling 为true时,调用NextFe ...

  7. 如何让MyEclispe中英文切换

    我们通过网上的一些汉化办法汉化了我们的MyEclipse,可是我们有时候想切回英文版怎么办? 方法一:我们可以通过修改MyEclipse配置文件的办法来从中文恢复到英文, -Duser.languag ...

  8. 你好,C++(1)C++是什么?C++的“前世今生”

    The world is built on C++. ——Herb Sutter the chairman of the ISO C++ standards committee and chief n ...

  9. 【回忆1314】回忆之placeholder

    直接看效果点这里 HTML <!DOCTYPE html> <html> <head lang="zh-CN"> <meta charse ...

  10. 转载:JAVA中使用JSON进行数据传递

    转载网址:http://www.cnblogs.com/undead/archive/2012/07/18/2594900.html 最近在做一个基于JAVA Servlet的WEB应用以及对应的An ...