Answer the question
In order to leave comments, you need to log in
Problems with encoding. How to decide?
Good afternoon, I ask for your help!
I am using python3.X. and I'm trying to pull out the geocode of the address using Yandex.maps.
If the address is in English, then there are no problems.
import urllib.request
def get_html(url):
response = urllib.request.urlopen(url)
return response.read()
yandex = 'https://geocode-maps.yandex.ru/1.x/?format=json&geocode=Moscow, Sretenka 8'
get_html(yandex).decode('utf-8')
Answer the question
In order to leave comments, you need to log in
from urllib.parse import quote
from urllib import request
def get_html(url):
response = request.urlopen(url)
return response.read()
yandex_ru = "https://geocode-maps.yandex.ru/1.x/?format=json&geocode={0}"
get_html(yandex_ru.format(quote("Москва, Сретенка 8"))).decode("utf-8")
1) Error in the studio
2) Methods how to solve - also desirable here
3) How do you set the Russian address? Are you writing directly to a variable? You must then specify the encoding at the beginning of the file ( stackoverflow.com/questions/3198765/how-to-write-r... ). In general - get used to the good right away - put the address in the config, for example. And the problem will be solved immediately.
and exactly you call the 3rd python?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
is this at the beginning of the file?
well, even in the second it should work fine with # -*- coding: utf-8 -*- and prefix u before the line: i.e.:
yandex = u' https://geocode-maps.yandex.ru/1.x /?format=json&ge... , Sretenka 8'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question