最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - pgeocode not returning CA locations - Stack Overflow

programmeradmin5浏览0评论

I am using pgeocode library to fetch city and state from pincodes. The library works fine for most countries, but not for Canada. I cross checked with suggested country list and CA is one of them. Also, I remember me testing CA before and cant recollect having issues before. I am using this library in a npm library package. This is my server.py

country = data.get("country")
postal_code = data.get("postal_code")

if not country or not postal_code:
    return jsonify({"error": "Country and postal code are required"}), 400

nomi = pgeocode.Nominatim(country)
location = nomi.query_postal_code(postal_code)
if location.empty:
    return jsonify({"error": "Invalid postal code"}), 404

return jsonify({
    "country": country,
    "postal_code": postal_code,
    "city": location.place_name,
    "state": location.state_name
})

This is what I receive and when I input postal code as "L2P2K6" and country as "CA", this is what it returns:

==counytry nomi CA
==counytry location postal_code       L2P2K6
country_code         NaN
place_name           NaN
state_name           NaN
state_code           NaN
county_name          NaN
county_code          NaN
community_name       NaN
community_code       NaN
latitude             NaN
longitude            NaN
accuracy             NaN
Name: 0, dtype: object

What am I doing wrong?

I am receiving positive response for most of the other postal codes. Example:

==counytry nomi US
==counytry location postal_code          60602
country_code            US
place_name         Chicago
state_name        Illinois
state_code              IL
county_name           Cook
county_code           31.0
community_name         NaN
community_code         NaN
latitude           41.8829
longitude         -87.6321
accuracy               4.0
发布评论

评论列表(0)

  1. 暂无评论