Python 3.x OpenStreetMap:Python 3的HTTP基本身份验证
我正试图通过Python脚本编写一些 OSMAPI应该支持HTTP基本身份验证 通过遵循Python文档中的示例,我编写了以下脚本:Python 3.x OpenStreetMap:Python 3的HTTP基本身份验证,python-3.x,basic-authentication,openstreetmap,Python 3.x,Basic Authentication,Openstreetmap,我正试图通过Python脚本编写一些 OSMAPI应该支持HTTP基本身份验证 通过遵循Python文档中的示例,我编写了以下脚本: #!/usr/bin/env python3 import urllib.request import urllib.parse url = 'http://api.openstreetmap.org/api/0.6/notes' username = 'Stemby' password = input('password > ') # Create
#!/usr/bin/env python3
import urllib.request
import urllib.parse
url = 'http://api.openstreetmap.org/api/0.6/notes'
username = 'Stemby'
password = input('password > ')
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='Web Password',
uri=url, user=username,
passwd=password)
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
def send_note(lat, lon, text):
data = dict(lat=lat, lon=lon, text=text)
urllib.request.urlopen(url, urllib.parse.urlencode(data).encode('utf8'))
lat = input('lat > ')
lon = input('lon > ')
text = input('text > ')
send_note(lat, lon, text)
我发现了这个领域
这样我可以创建新的注释,但这些注释是匿名的;所以身份验证不起作用
你能帮我吗
我正在Debian Jessie上使用Python 3.2.4
谢谢大家! 通过使用解决。在Debian上,包名是“python3请求”
这是我的剧本:
#!/usr/bin/env python3
import requests
url = 'http://api.openstreetmap.org/api/0.6/notes'
username = input('username > ')
password = input('password > ')
def send_note(lat, lon, text):
data = dict(lat=lat, lon=lon, text=text)
requests.post(url, data=data, auth=(username, password))
lat = input('lat > ')
lon = input('lon > ')
text = input('text > ')
send_note(lat, lon, text)
再见 你知道吗?不,我不知道。我试试看。非常感谢你!