11import requests
22import json
33import geojson
4+ import logging
45
56from .errors import (OverpassSyntaxError , TimeoutError , MultipleRequestsError ,
67 ServerLoadError , UnknownOverpassError , ServerRuntimeError )
@@ -11,7 +12,7 @@ class API(object):
1112 SUPPORTED_FORMATS = ["geojson" , "json" , "xml" ]
1213
1314 # defaults for the API class
14- _timeout = 25 # seconds
15+ _timeout = 25 # second
1516 _endpoint = "http://overpass-api.de/api/interpreter"
1617 _debug = False
1718
@@ -25,16 +26,22 @@ def __init__(self, *args, **kwargs):
2526 self ._status = None
2627
2728 if self .debug :
28- import httplib
29- import logging
30- httplib .HTTPConnection .debuglevel = 1
31-
29+ # http://stackoverflow.com/a/16630836
30+ try :
31+ import http .client as http_client
32+ except ImportError :
33+ # Python 2
34+ import httplib as http_client
35+ http_client .HTTPConnection .debuglevel = 1
36+
37+ # You must initialize logging, otherwise you'll not see debug output.
3238 logging .basicConfig ()
3339 logging .getLogger ().setLevel (logging .DEBUG )
3440 requests_log = logging .getLogger ("requests.packages.urllib3" )
3541 requests_log .setLevel (logging .DEBUG )
3642 requests_log .propagate = True
3743
44+
3845 def Get (self , query , responseformat = "geojson" , verbosity = "body" , build = True ):
3946 """Pass in an Overpass query in Overpass QL"""
4047
@@ -43,6 +50,9 @@ def Get(self, query, responseformat="geojson", verbosity="body", build=True):
4350 full_query = self ._ConstructQLQuery (query , responseformat = responseformat , verbosity = verbosity )
4451 else :
4552 full_query = query
53+
54+ if self .debug :
55+ logging .getLogger ().info (query )
4656
4757 # Get the response from Overpass
4858 raw_response = self ._GetFromOverpass (full_query )
0 commit comments