Skip to content

Commit

Permalink
Avoid 500 server error with IPv6 addresses (GeoIP)
Browse files Browse the repository at this point in the history
I get 500 Server errors when searching for resources with a non-empty string.
With DEBUG=True I can get the exception: "Invalid database type; expected IPv4 address" which is backtraced to the getcountry_code function in the stats/geoip.py file.

The proposed try/except patch fixes the issue by returning the default empty string if geoip cannot find the country.

As far as I know, this is used for statistic purposes, so providing the country guessed by the IP it is not crucial for metashare.
  • Loading branch information
zeehio committed Oct 17, 2014
1 parent 4c28d70 commit eadff69
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion metashare/stats/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ def getcountry_coords(countrycode):

def getcountry_code(ipaddress):
if (ipaddress != "" and not is_privateIP(ipaddress)):
return geoip.country_code_by_addr(ipaddress)
try:
return geoip.country_code_by_addr(ipaddress)
except pygeoip.GeoIPError:
return ""
return ""

0 comments on commit eadff69

Please sign in to comment.