@@ -104,45 +104,50 @@ Async Web Service Example
104104
105105.. code-block :: pycon
106106
107+ >>> import asyncio
108+ >>>
107109 >>> import geoip2.webservice
108110 >>>
109- >>> # This creates an AsyncClient object that can be reused across
110- >>> # requests on the running event loop. If you are using multiple event
111- >>> # loops, you must ensure the object is not used on another loop.
112- >>> #
113- >>> # Replace "42" with your account ID and "license_key" with your license
114- >>> # key.
115- >>> async with geoip2.webservice.AsyncClient(42, 'license_key') as client:
111+ >>> async def main():
112+ >>> # This creates an AsyncClient object that can be reused across
113+ >>> # requests on the running event loop. If you are using multiple event
114+ >>> # loops, you must ensure the object is not used on another loop.
115+ >>> #
116+ >>> # Replace "42" with your account ID and "license_key" with your license
117+ >>> # key.
118+ >>> async with geoip2.webservice.AsyncClient(42, 'license_key') as client:
116119 >>>
117- >>> # Replace "insights" with the method corresponding to the web service
118- >>> # that you are using, e.g., "country", "city".
119- >>> response = await client.insights('203.0.113.0')
120+ >>> # Replace "insights" with the method corresponding to the web service
121+ >>> # that you are using, e.g., "country", "city".
122+ >>> response = await client.insights('203.0.113.0')
120123 >>>
121- >>> response.country.iso_code
124+ >>> response.country.iso_code
122125 'US'
123- >>> response.country.name
126+ >>> response.country.name
124127 'United States'
125- >>> response.country.names['zh-CN']
128+ >>> response.country.names['zh-CN']
126129 u'美国'
127130 >>>
128- >>> response.subdivisions.most_specific.name
131+ >>> response.subdivisions.most_specific.name
129132 'Minnesota'
130- >>> response.subdivisions.most_specific.iso_code
133+ >>> response.subdivisions.most_specific.iso_code
131134 'MN'
132135 >>>
133- >>> response.city.name
136+ >>> response.city.name
134137 'Minneapolis'
135138 >>>
136- >>> response.postal.code
139+ >>> response.postal.code
137140 '55455'
138141 >>>
139- >>> response.location.latitude
142+ >>> response.location.latitude
140143 44.9733
141- >>> response.location.longitude
144+ >>> response.location.longitude
142145 -93.2323
143146 >>>
144- >>> response.traits.network
147+ >>> response.traits.network
145148 IPv4Network('203.0.113.0/32')
149+ >>>
150+ >>> asyncio.run(main())
146151
147152 Web Service Client Exceptions
148153-----------------------------
0 commit comments