Skip to main content

Common errors

Use the diagnostic flow below to match what your HTTP client or browser console reports to the underlying root cause and recovery pattern.

400 Bad Request​

Symptom and error payload​

The API rejects the query string before running a lookup and returns HTTP 400 with "cod": "400" (formatted as a string):

{
"cod": "400",
"message": "Nothing to geocode"
}

Invalid geographic coordinates produce a coordinate-specific message:

{
"cod": "400",
"message": "wrong latitude"
}

Root causes and solutions​

Root causeResolution
Empty search input (?q=&appid=...) submitted before user typing completesTrim and validate that q or zip is non-empty before dispatching the request.
Uninitialized JavaScript variables serialized as literals (?lat=undefined&lon=NaN)Guard numeric coordinates with Number.isFinite(lat) && Number.isFinite(lon) prior to calling fetch.
Swapped GeoJSON coordinate order ([lon, lat] passed as lat and lon)Confirm lat lies within -90 to 90 and lon lies within -180 to 180.
Unencoded # or & characters inside location text truncating the URLConstruct URLs with URLSearchParams in JavaScript or params={...} in Python rather than string concatenation.

Diagnostic check​

Log the serialized request URL with appid redacted and verify that either q or both lat and lon contain well-formed values:

curl -i "https://api.openweathermap.org/data/2.5/weather?lat=51.5074&lon=-0.1278&units=metric&appid=$OPENWEATHER_API_KEY"

401 Unauthorized​

Symptom and error payload​

OpenWeatherMap rejects authentication and returns HTTP 401 with an integer cod value:

{
"cod": 401,
"message": "Invalid API key."
}

Root causes and solutions​

Root causeResolution
Newly created API key is still propagating across edge gatewaysWait 10–15 minutes (and up to 2 hours in peak propagation windows) after creating a key before retesting. Do not delete and recreate the key while waiting, which resets the timer.
Calling One Call API 3.0 (/data/3.0/onecall) or paid endpoints on a free keyFree keys authorize /data/2.5/weather, /data/2.5/forecast, and /geo/1.0/* without billing setup. Calling /data/3.0/onecall, /data/2.5/forecast/daily, or historical endpoints without an active subscription returns 401 Unauthorized.
Missing, misspelled, or whitespace-padded appid parameterPass the credential as lowercase appid= (not api_key= or key=) and call .trim() on environment variables to strip trailing newline characters from .env files.
Key was deactivated or deleted in your accountSign in to the OpenWeatherMap API keys dashboard and confirm the key status reads Active.

Diagnostic check​

Isolate your API key from application code and .env loaders by testing a free-tier 2.5 endpoint directly from your terminal:

curl -i "https://api.openweathermap.org/data/2.5/weather?q=London,GB&appid=$OPENWEATHER_API_KEY"

If this command returns HTTP/2 200 while your application receives 401, check whether your code targets /data/3.0/onecall or reads an empty environment variable. For credential setup details, see Authentication.

404 Not Found and empty geocoding arrays​

Symptom and error payload​

Missing locations surface differently depending on which OpenWeatherMap service you call:

  • Weather API 2.5 (/data/2.5/weather and /data/2.5/forecast) returns HTTP 404 Not Found with "cod": "404" as a string:
{
"cod": "404",
"message": "city not found"
}
  • Geocoding API 1.0 (/geo/1.0/direct) returns HTTP 200 OK with an empty JSON array when no location matches—causing unguarded data[0].lat reads to throw a runtime TypeError:
[]

Root causes and solutions​

Root causeResolution
Omitted service prefix (such as requesting /weather instead of /data/2.5/weather)Include the full versioned endpoint path (/data/2.5/weather, /data/2.5/forecast, or /geo/1.0/direct).
Ambiguous, localized, or unencoded city name in ?q=URL-encode non-ASCII characters and spaces (São%20Paulo), or switch to the two-step Query weather by coordinates workflow.
US state code supplied without ISO 3166 country code (?q=Austin,TX)Append ,US whenever specifying a US state (?q=Austin,TX,US).
Non-US postal code passed to /geo/1.0/zip without a country code/geo/1.0/zip defaults to the United States when country is omitted; append the two-letter ISO country code (?zip=SW1A,GB).
Unchecked empty array from /geo/1.0/directVerify Array.isArray(results) && results.length > 0 before reading results[0].

Diagnostic check​

Query the Geocoding API directly with limit=5 to inspect matching candidates and their canonical coordinates:

curl -s "https://api.openweathermap.org/geo/1.0/direct?q=Springfield,IL,US&limit=5&appid=$OPENWEATHER_API_KEY"

429 Too Many Requests​

Symptom and error payload​

Exceeding your subscription's burst or monthly quota returns HTTP 429:

{
"cod": 429,
"message": "Your account is temporary blocked due to exceeding of requests limitation of your subscription type."
}

Root causes and solutions​

Root causeResolution
Exceeding 60 calls per minute across all keys on your accountQuotas pool across your entire OpenWeatherMap account rather than per individual key. Add a 10-minute backend cache instead of rotating extra keys.
Runaway frontend useEffect or reactive state loopOpen your browser DevTools Network tab to verify your component isn't re-fetching on every render; debounce search inputs by 300–500 ms.
Unthrottled Promise.all or tight loop in scheduled batch jobsSpace sequential batch requests by at least 1,100 ms (~54 requests/minute) and back off exponentially when 429 occurs.
Direct client requests scaling linearly with concurrent website visitorsMove OpenWeatherMap calls behind a shared caching proxy—see Set up rate limiting and caching.

Diagnostic check​

When running background sync scripts across multiple saved cities, pace sequential calls so total throughput stays safely below 60 requests per minute:

const PACE_INTERVAL_MS = 1100;
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

for (let i = 0; i < locations.length; i += 1) {
const weather = await fetchWeatherByCoordinates(locations[i].lat, locations[i].lon);
results.push(weather);

if (i < locations.length - 1) {
await pause(PACE_INTERVAL_MS);
}
}

For full exponential backoff and retry logic on 429 responses, see Handle errors in production.

Browser CORS preflight and mixed content errors​

Symptom and error payload​

No HTTP status code reaches your JavaScript fetch handler; instead, the browser console logs a Cross-Origin Resource Sharing (CORS) or mixed-content security error:

Access to fetch at 'https://api.openweathermap.org/data/2.5/weather?...' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check.

Or on an https:// site calling an http:// endpoint:

Mixed Content: The page at 'https://example.com' was loaded over HTTPS, but requested an insecure resource 'http://api.openweathermap.org/...'. This request has been blocked.

Root causes and solutions​

Root causeResolution
Custom request headers (Authorization, Content-Type: application/json, X-Requested-With, or Cache-Control) attached by frontend HTTP interceptorsPreflight-exempt GET requests carry no custom headers. Adding non-CORS-safelisted headers forces the browser to send an OPTIONS preflight check, which api.openweathermap.org rejects. Remove custom headers—or move the request to your backend.
Hardcoded http://api.openweathermap.org URL called from an https:// pageAlways use https://api.openweathermap.org so browsers never block the request as mixed content.
Calling OpenWeatherMap directly from production browser JavaScriptRoute frontend requests through your own backend proxy or serverless route (GET /api/weather), which eliminates browser CORS restrictions, hides appid from DevTools, and shares a 10-minute cache across users. See API architecture overview.

Diagnostic check​

Inspect the Network tab in browser DevTools and look at the Method column:

  1. If you see a failed OPTIONS request preceding your GET request, inspect Request Headers to find which global Axios or Fetch interceptor injected Authorization or Content-Type.
  2. Verify the target URL starts with https://api.openweathermap.org and passes appid in the query string on your backend proxy.

Unexpected or missing payload fields​

When a request succeeds with 200 OK yet your UI renders implausible numbers or undefined properties, check these OpenWeatherMap schema behaviors:

Observed symptomRoot causeResolution
Temperature reads 280–310Omitting units returns Kelvin (K) under the default standard unit system.Append &units=metric (°C) or &units=imperial (°F), or convert in UI code. See Unit systems and conversions.
rain, snow, or wind.gust is undefinedOpenWeatherMap omits optional precipitation and gust objects whenever accumulation is zero or unmeasured.Read optional fields defensively (data.rain?.['1h'] ?? 0 in JavaScript or data.get("rain", {}).get("1h", 0.0) in Python).
main.temp_min equals main.temp_maxIn /data/2.5/weather, those fields reflect current spatial spread across stations in a metro area, not 24-hour daily lows and highs.Compute daily extremes across intervals in /data/2.5/forecast. See How weather data works.
dt lags behind current time by up to 10 minutesdt records when the meteorological observation snapshot was calculated (refreshed every 10 minutes), not HTTP response time.Cache responses for 10 minutes instead of re-polling for newer timestamps.
pressure is 1013 and rain.1h is in mm despite units=imperialunits modifies only temperature and wind speed; pressure (hPa), precipitation (mm), and visibility (m) always remain in SI units.Convert mm ÷ 25.4 for inches and hPa × 0.02953 for inHg. See Unit systems and conversions.
Strict data.cod === 200 check failscod is serialized as a number (200) in /data/2.5/weather and as a string ("200") in /data/2.5/forecast.Branch on the HTTP transport status (response.ok or response.status) instead of data.cod.