michaeldorman / mapsapi

'sf'-Compatible Interface to Google Maps APIs
Other
50 stars 14 forks source link

Timeout Errors #14

Closed noellemetro closed 3 years ago

noellemetro commented 3 years ago

While I am running mapsapi::mp_geocode, I cannot geocode more than 10 in any list before receive this error:

Error in open.connection(x, "rb") : 
Timeout was reached: [maps.googleapis.com] Operation timed out after 10000 milliseconds with 0 out of 0 bytes received

I have tried to set this timeout response manually but have not had luck.

It's very hard to reproduce this result because of it is dependent on the full traceback failure inside xml2:

+ mp_geocode(addresses = sheet$test,
+            key = key,
+            quiet = FALSE)
https://maps.googleapis.com/maps/api/geocode/xml?address=1302%20Railside%20Dr%20Gibson%20City%20IL%2060936&key=PPP
1302 Railside Dr Gibson City IL 60936...OK
https://maps.googleapis.com/maps/api/geocode/xml?address=1302%20Railside%20Dr%20Gibson%20City%20IL%2060936&key=PPP
1302 Railside Dr Gibson City IL 60936...OK
https://maps.googleapis.com/maps/api/geocode/xml?address=117%20W%2011th%20Gibson%20City%20IL%2060936&key=PPP
117 W 11th Gibson City IL 60936.........OK
https://maps.googleapis.com/maps/api/geocode/xml?address=120%20W%2011th%20Gibson%20City%20IL%2060936&key=PPP
120 W 11th Gibson City IL 60936.........OK
https://maps.googleapis.com/maps/api/geocode/xml?address=212%20W%2010th%20Gibson%20City%20IL%2060936&key=PPP
 Error in open.connection(x, "rb") : 
Timeout was reached: [maps.googleapis.com] Operation timed out after 10003 milliseconds with 0 out of 0 bytes received

Traceback: 

6.
open.connection(x, "rb")
5.
open(x, "rb")
4.
read_xml.connection(con, encoding = encoding, ..., as_html = as_html, 
base_url = x, options = options)
3.
read_xml.character(url)
2.
xml2::read_xml(url)
1.
mp_geocode(addresses = sheet$test, key = key, quiet = FALSE)

I'm going through the traceback and I'm wondering if it may be possible to manually set the timeout number. I've tried global options and there may be a spot in the traceback for such a timeout variable.

The function only appears to be problematic when geocoding has returned XML and it takes longer than 10 seconds.

A lot of this is beyond my skill but I wanted to drop this issue here. I can confirm my API key is working normally and my server admin has also confirmed that there is not a rule that would cause this issue.

michaeldorman commented 3 years ago

Hi,

Like you said, I cannot reproduce the issue. It may be related to the internet connection.

  1. I added a timeout option in mp_geocode: https://github.com/michaeldorman/mapsapi/commit/efb843b38defd0e18ceebf9ec74a65e5c1a75b37 according to an example in this thread: https://github.com/ropensci/rtweet/issues/229

    Please try to install the development version of mapsapi:

    remotes::install_github("michaeldorman/mapsapi") 

    and then set a larger timeout in mp_geocode (default is 10 seconds):

    mp_geocode("212 W 10th Gibson City IL 60936", key = ..., timeout = 60)

    Will be happy to hear if this helped or not.

  2. Also please check out the recommendation here: https://stackoverflow.com/questions/54624278/getting-connection-timed-out-error-while-geocoding-in-r

Thanks and Best regards,

Michael

noellemetro commented 3 years ago

Hi Michael,

The updated function worked perfectly and resolved the issue for me.

Thank you for your time!

Best,

Noelle

michaeldorman commented 3 years ago

Great, glad to hear!