Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python 3.x urllib.request.urlopen西里尔文内容在站点->403_Python_Urllib_Cyrillic - Fatal编程技术网

python 3.x urllib.request.urlopen西里尔文内容在站点->403

python 3.x urllib.request.urlopen西里尔文内容在站点->403,python,urllib,cyrillic,Python,Urllib,Cyrillic,我得到HTTP错误403:禁止,因为网站上有西里尔字母 范例 如果我在google.com上替换google.ru,那么一切都正常。可能还有其他原因导致出现403错误。这与网站上的内容无关。尝试打印HTTPError的内容,以查看是否获得有关该错误的更多信息。我添加了用户代理,但没有帮助。 import urllib.request def forum(request): with urllib.request.urlopen("http://www.google.ru") as ur

我得到HTTP错误403:禁止,因为网站上有西里尔字母

范例


如果我在google.com上替换google.ru,那么一切都正常。

可能还有其他原因导致出现403错误。这与网站上的内容无关。尝试打印HTTPError的内容,以查看是否获得有关该错误的更多信息。我添加了用户代理,但没有帮助。
import urllib.request

def forum(request):
    with urllib.request.urlopen("http://www.google.ru") as url:
        s = url.read().decode().encode('utf-8')
    return HttpResponse(s)