![]() |
Web connection delay - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Web connection delay (/thread-17167.html) |
Web connection delay - ebolisa - Mar-31-2019 Hi, This link displays the local country data and the server response is immediate: However, getting the same data from using the below code, takes some time. Why the delay? TIA #!/usr/bin/python import requests as req from xml.etree import ElementTree as ET import os, time def get_tz(): url = 'http://geoip.ubuntu.com/lookup' #read file r = req.get(url) if(r.status_code == req.codes.ok): root = ET.fromstring(r.content) # parse an xml file by name TZ = "'" + root[12].text + "'" t = r.elapsed # returns datetime.timedelta(0, 1, 666890) #print('elapsed time: {}'.format(t)) print(TZ) #update time os.environ['TZ'] = TZ time.tzset() get_tz() RE: Web connection delay - micseydel - Apr-02-2019 How much time? It's virtually instantaneous for me. RE: Web connection delay - aishyoung056 - Apr-22-2019 whaats your topic RE: Web connection delay - Larz60+ - Apr-22-2019 Quote:micseydel writes: How much time? It's virtually instantaneous for me.I also find it nearly instantaneous. Are you going through a firewall? RE: Web connection delay - micseydel - Apr-23-2019 The other thing that might be happening is they detected too many requests from your IP + user agent combo and they're rate-limiting you. The solution to that is either wait (it wouldn't surprise me if it works for you now), change your user agent (kinda evil) or figure out the right policy (do they have an API?) and work from there. RE: Web connection delay - DeaD_EyE - Apr-23-2019 By the way, you can use the find method on an Element. root = ET.fromstring(r.content) TZ = resp.find('TimeZone').textAnother trick to make from a flat xml structure a dict: result = {e.tag: e.text for e in resp} You should not run your script to often. Otherwise -> RateLimit
|