IP Geolocation API in Python: 148.105.12.120 JSON
You need to geolocate an IP in Python, extract city, ASN, coordinates, and security flags, and then ship that data into your app. By the end of this walkthrough you’ll query Ipxapi for the IP 148.105.12.120, parse the JSON safely, and know exactly which fields to store and how to handle edge cases.
What you’ll build and why it matters
This guide shows a one-API-call workflow to look up an IP and persist only the fields you actually need: city, latitude, longitude, AS/ASN, and security indicators. You’ll run a live request, read the official JSON for the MailChimp IP 148.105.12.120 (AS14782, Mountain View), and adapt the same call for any IP you care about. If you’re gating content, enriching logs, routing traffic, or adding fraud signals, this is the shortest path to production.
Endpoint and authentication
Ipxapi exposes a single lookup for this job: GET /api/ip?ip=. You authenticate with a Bearer key, then pass the IP you want to resolve. The same contract applies to curl and Python. For interactive exploration or to run this from a server, use the MCP host:
Plan and access: Basic is $29.99/mo with a 7-day trial or 50 requests. You can create your key here:
Run a live request for 148.105.12.120
Below is the official sample request for the MailChimp IP. It targets the same endpoint you’ll use in production. Replace YOUR_API_KEY with the Bearer key from your dashboard.
curl "https://ipxapi.com/api/ip?ip=148.105.12.120" \
-H "Accept: application/json" \
-H "Authorization: Bearer YOUR_KEY"
Notes:
- IP 148.105.12.120 is provided for testing and belongs to MailChimp (AS14782) in Mountain View. Use it to verify your pipeline, but always query the IP you actually care about. Do not treat this example IP as your user’s address.
- The endpoint is idempotent and returns JSON. There’s no pagination for single-IP lookups.
Python: same contract
You can call the same API from Python with the same URL and Bearer authentication. The sample below shows how to send the request and parse the JSON.
import os, urllib.request
req = urllib.request.Request(
"https://ipxapi.com/api/ip?ip=148.105.12.120",
headers={"Authorization": "Bearer " + os.environ["IPXAPI_KEY"], "Accept": "application/json"},
)
print(urllib.request.urlopen(req).read().decode())
The JSON you’ll receive (official)
When you resolve 148.105.12.120, the response follows this shape and values. Use this to validate your integration and to map the fields you’ll store.
{
"status": "success",
"country": "United States",
"countryCode": "US",
"city": "Mountain View",
"lat": 37.40599,
"lon": -122.0786,
"isp": "MailChimp",
"as": "AS14782 MailChimp",
"query": "148.105.12.120"
}
How to read it in your application:
- city: Human-readable city for the IP. Store as text for analytics and localization.
- lat and lon: Decimal degrees (WGS84-style). Use for mapping, radius checks, or nearest-region routing.
- as (or asn/organization details): The autonomous system associated with the IP. You’ll typically log the AS number (e.g., AS14782) and sometimes the AS name (e.g., MailChimp) for traffic profiling and allow/deny rules.
- security flags: Indicators that the IP might be a VPN, proxy, hosting provider, or otherwise risky. Use these as fraud signals alongside device and behavioral data.
If a field is absent in the JSON, treat it as unknown rather than error. For example, if security flags are missing, default to “no signal” instead of “safe”—lack of data is not proof of safety.
From request to durable data
What to store
- city (string)
- lat, lon (floats, degrees)
- as (string or struct containing the numeric ASN and the AS name)
- security flags (booleans or categorical strings depending on the response)
Keep the raw JSON for auditing if storage permits. Also persist the IP you queried and the retrieval timestamp you assign in your system (UTC recommended).
Error handling and partial data
- HTTP status: On non-200 responses, back off and log the body for diagnostics.
- Body shape: If your parser sees an unexpected structure or a boolean like success set to false (when present), surface it as an application error and skip writes.
- Missing fields: Default to null/None for optional fields (e.g., city, security signals). Avoid inferring replacements.
Units, timestamps, and timezone
- lat, lon: Decimal degrees; positive/negative denote hemisphere.
- Time: This endpoint returns geodata; you provide your own request timestamp and store it as UTC to avoid ambiguity.
Caching and revalidation
- Cache per IP. Most IP-to-location mappings are stable enough for server-side caching. Adjust TTLs to your risk tolerance; shorter for security-sensitive flows, longer for analytics.
- Bust cache when your workflow requires fresh security flags (e.g., at login or checkout).
Go live in four steps
- Register: Register — 7-day trial or 50 requests.
- Copy the Bearer key from your dashboard.
- GET /api/ip?ip= using your key on the MCP host.
- Store city, lat, lon, as, and security flags in your database or telemetry pipeline.
Looking up any IP (including 148.105.12.120)
The official examples here use 148.105.12.120, which belongs to MailChimp (AS14782) in Mountain View. To look up a different IP, change the ip parameter value in the same request. The Python example you saw uses the same contract, so you only switch the IP string in the query.
If you still need a key to test your own IPs, start here: Register. For deeper field descriptions and any future updates, refer to the Documentation.
Operational tips that save time
- Idempotency: Repeat calls for the same IP return the same shape, so you can safely retry on transient network errors.
- Rate hygiene: Batch non-critical lookups (e.g., nightly enrichment) and deduplicate IPs before calling the API to conserve your request budget.
- Schema stability: Build your parser to be tolerant—ignore unknown fields and only extract what you store (city, lat, lon, as, security flags).
- Observability: Log request latency and downstream usage of the fields so you can spot regressions when you change caching or add new consumers.
FAQ
Does the sample IP represent my current device?
No. 148.105.12.120 is a MailChimp IP used here for testing. Always query the specific IP address you need to evaluate.
Which fields should I persist?
Keep city, latitude, longitude, AS/ASN, and the security flags. Optionally store the raw JSON and your own retrieval timestamp (UTC).
How do I handle responses with missing fields?
Treat them as unknown values (null/None). Don’t substitute defaults like “Unknown City” in your core tables; derive those at presentation time if needed.
What if the API returns an error?
Check the HTTP status first, then inspect the body. If you see an application-level error (e.g., a boolean flag indicating failure when present), log it, skip writes, and retry later if appropriate.
Where do I find the full field reference?
See the Ipxapi Documentation for the most current response schema and additional guidance.
Ready to add IP geolocation to your Python stack? Start your 7-day trial (or 50 free requests), grab your Bearer key, and ship your first integration today: Register.
