Closed Becase closed 5 months ago
你好,试试把命令行参数quote起来再运行一下? lat=xx, lon=xx应该是你隐去了吧,可以再看看报错这行,实际的经纬度格式是否正确?
你好,试试把命令行参数quote起来再运行一下? lat=xx, lon=xx应该是你隐去了吧,可以再看看报错这行,实际的经纬度格式是否正确?
请问怎么quote,我将代理地址增加引号后尝试执行:
./teslamate-addr-fix -db myteslamate -host 172.17.0.1 -password password -user teslamate -port 5432 -proxy “http://192.168.1.88:18888” -timeout 15
输出:psql_client.go:193: get address from osm failed, lat=xx.xxxx65, lon=xx.xxxx84, err=osm returns error status, status=403, url=https://nominatim.openstreetmap.org/reverse?lat=xx.xxxx65&lon=xx.xxxx84&format=json
./teslamate-addr-fix -db myteslamate -host '172.17.0.1' -password password -user teslamate -port 5432 -proxy 'http://192.168.1.88:18888' -timeout 15
试试这样
应该是go http.Client默认的user-agent被openstreetmap阻止访问了
curl "https://nominatim.openstreetmap.org/reverse?lat=19.913121&lon=110.316397&format=json" -x http://192.168.1.88:18888 --user-agent "curl/[7.86.0]"
{"place_id":237646966,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright","osm_type":"way","osm_id":220068262,"lat":"19.91281585","lon":"110.31585813238507","class":"amenity","type":"parking","place_rank":30,"importance":9.99999999995449e-06,"addresstype":"amenity","name":"","display_name":"羊山大道, 龙华区, 海口市, 海南省, 571155, 中国","address":{"road":"羊山大道","city":"龙华区","state":"海南省","ISO3166-2-lvl4":"CN-HI","postcode":"571155","country":"中国","country_code":"cn"},"boundingbox":["19.9119490","19.9136180","110.3150186","110.3166638"]}
curl "https://nominatim.openstreetmap.org/reverse?lat=19.913121&lon=110.316397&format=json" -x http://192.168.1.88:18888 --user-agent "Go-http-client/1.1"
<html>
<head>
<title>Access blocked</title>
</head>
<body>
<h1>Access blocked</h1>
<p>You have been blocked because you have violated the
<a href="https://operations.osmfoundation.org/policies/nominatim/">usage policy</a>
of OSM's Nominatim geocoding service. Please be aware that OSM's resources are
limited and shared between many users. The usage policy is there to ensure that
the service remains usable for everybody.</p>
<p>Please review the terms and make sure that your
software adheres to the terms. You should in particular verify that you have set a
<b>custom HTTP referrer or HTTP user agent</b> that identifies your application, and
that you are not overusing the service with massive bulk requests.</p>
<p>If you feel that this block is unjustified or remains after you have adopted
your usage, you may contact the Nominatim system administrator at
nominatim@openstreetmap.org to have this block lifted.</p>
</body>
</head>
curl "https://nominatim.openstreetmap.org/reverse?lat=19.913121&lon=110.316397&format=json" -x http://192.168.1.88:18888 --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
{"place_id":237646966,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright","osm_type":"way","osm_id":220068262,"lat":"19.91281585","lon":"110.31585813238507","class":"amenity","type":"parking","place_rank":30,"importance":9.99999999995449e-06,"addresstype":"amenity","name":"","display_name":"羊山大道, 龙华区, 海口市, 海南省, 571155, 中国","address":{"road":"羊山大道","city":"龙华区","state":"海南省","ISO3166-2-lvl4":"CN-HI","postcode":"571155","country":"中国","country_code":"cn"},"boundingbox":["19.9119490","19.9136180","110.3150186","110.3166638"]}
这也就是为什么我的代理可以curl到,但是teslamate-addr-fix无法获取地址的原因吧。
const (
osmReverseURL = "https://nominatim.openstreetmap.org/reverse?lat=%.6f&lon=%.6f&format=json"
chromeUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
)
func getAddressByProxy(latitude, longitude float64) (*OsmRevAddress, error) {
if latitude == 0 && longitude == 0 {
return nil, fmt.Errorf("arg error, latitude=0, longitude=0")
}
/*
reqURL := fmt.Sprintf(osmReverseURL, latitude, longitude)
fmt.Println("START--------------------")
fmt.Println(reqURL)
fmt.Println("cli is null:", cli == nil)
rsp, err := cli.Get(reqURL)
fmt.Println("rsp:", rsp)
fmt.Println("err:", err)
if err != nil {
return nil, err
}
*/
reqURL := fmt.Sprintf(osmReverseURL, latitude, longitude)
// 创建一个新的 HTTP 请求
req, err := http.NewRequest("GET", reqURL, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return nil, err
}
// 设置 User-Agent 头部
req.Header.Set("User-Agent", chromeUserAgent)
// req.Header.Set("User-Agent", curlUserAgent)
// req.Header.Set("User-Agent", golangUserAgent)
rsp, err := cli.Do(req)
if err != nil {
return nil, err
}
……
作者你好,感谢你提供的修复工具。
不添加代理curl
执行
curl -v "https://nominatim.openstreetmap.org/reverse?lat=19.913121&lon=110.316397&format=json"
输出如下: `添加代理curl
部署环境用代理可以curl到地址,如下:
curl -v "https://nominatim.openstreetmap.org/reverse?lat=19.913121&lon=110.316397&format=json" -x http://192.168.1.88:18888
输出日志如下: `teslamate-addr-fix加代理执行提示status=403
./teslamate-addr-fix -db myteslamate -host 172.17.0.1 -password password -user teslamate -port 5432 -proxy http://192.168.1.88:18888 -timeout 15
执行后提示:psql_client.go:233: get address from osm failed, lat=xx, lon=xx, err=osm returns error status, status=403, url=https://nominatim.openstreetmap.org/reverse?lat=xx&lon=xx&format=json
请问这是啥原因呢?