{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython-lib/issues/293","repository_url":"https://api.github.com/repos/micropython/micropython-lib","labels_url":"https://api.github.com/repos/micropython/micropython-lib/issues/293/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython-lib/issues/293/comments","events_url":"https://api.github.com/repos/micropython/micropython-lib/issues/293/events","html_url":"https://github.com/micropython/micropython-lib/issues/293","id":339252622,"node_id":"MDU6SXNzdWUzMzkyNTI2MjI=","number":293,"title":"Urequests delay","user":{"login":"fernandomorse","id":18339456,"node_id":"MDQ6VXNlcjE4MzM5NDU2","avatar_url":"https://avatars3.githubusercontent.com/u/18339456?v=4","gravatar_id":"","url":"https://api.github.com/users/fernandomorse","html_url":"https://github.com/fernandomorse","followers_url":"https://api.github.com/users/fernandomorse/followers","following_url":"https://api.github.com/users/fernandomorse/following{/other_user}","gists_url":"https://api.github.com/users/fernandomorse/gists{/gist_id}","starred_url":"https://api.github.com/users/fernandomorse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fernandomorse/subscriptions","organizations_url":"https://api.github.com/users/fernandomorse/orgs","repos_url":"https://api.github.com/users/fernandomorse/repos","events_url":"https://api.github.com/users/fernandomorse/events{/privacy}","received_events_url":"https://api.github.com/users/fernandomorse/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-08T19:51:47Z","updated_at":"2018-07-09T20:14:41Z","closed_at":"2018-07-09T20:14:41Z","author_association":"NONE","body":"When using the code example below:\r\n\r\n```\r\nimport time\r\nimport network\r\nimport urequests\r\n\r\ndef setNetworkConfig(ssid, pwd):\r\n    wlan = network.WLAN(network.STA_IF)\r\n    if not wlan.isconnected():\r\n        print('connecting to network...')\r\n        wlan.active(True)\r\n        wlan.connect(ssid, pwd)\r\n        while not wlan.isconnected():\r\n            pass\r\n    print('network config:' ,wlan.ifconfig())\r\n\r\ndef resourceLastFeeds(protocol,url,keyPublic,keySecret,id,silent=False):\r\n\r\n    # defining the api-endpoint\r\n    API_ENDPOINT = protocol+\"://\"+url+\"/api/device/\"+keyPublic+\"/resource/\"+str(id)+\"/feeds/last\"\r\n\r\n    #Headers\r\n    if keySecret is not None:\r\n        headers = {\"Authorization\":\"Bearer \"+keySecret,\"Content-Type\":\"application/json\"}\r\n    else:\r\n        headers = {\"Content-type\":\"application/json\"}\r\n\r\n    start = time.ticks_ms()  # get millisecond counter\r\n    # sending get\r\n    response = urequests.get(url = API_ENDPOINT,  headers=headers)\r\n    parsed = response.json()\r\n    response.close()\r\n    delta = time.ticks_diff(time.ticks_ms(), start)\r\n    print(\"Delay (ms): \",delta)\r\n    return\r\n\r\nsetNetworkConfig('SSID','PWD')\r\nresourceLastFeeds('http', 'automacao-iot.com.br', 'C8DE1A17E97BB0D363FF6FE5E40EC544','0502B74AC1B075AAC292F7D7FE3C27936E2F5E1E539E7F6A122164061A1469F6', 13)\r\n```\r\n\r\n\r\nI registered a delay of 5 seconds, from the request to the closing of the same \r\nCommenting on the **_#parsed = response.json()_**  line, the delay passes to 360 ms (same for response.text or response.content)\r\nReading the urequests library, self._cached = self.raw.read(), is responsible for the delay.\r\n\r\n```\r\nos.uname()\r\n(sysname='esp8266', nodename='esp8266', release='2.2.0-dev(9422289)', version='v1.9.4-8-ga9a3caad0 on 2018-05-11', machine='ESP module with ESP8266')\r\n\r\n```\r\nIs there any alternative to decrease this delay, using response.text, response.json or response.content ??\r\nAm I doing something wrong?"},"comment":{"url":"https://api.github.com/repos/micropython/micropython-lib/issues/comments/403605677","html_url":"https://github.com/micropython/micropython-lib/issues/293#issuecomment-403605677","issue_url":"https://api.github.com/repos/micropython/micropython-lib/issues/293","id":403605677,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzYwNTY3Nw==","user":{"login":"fernandomorse","id":18339456,"node_id":"MDQ6VXNlcjE4MzM5NDU2","avatar_url":"https://avatars3.githubusercontent.com/u/18339456?v=4","gravatar_id":"","url":"https://api.github.com/users/fernandomorse","html_url":"https://github.com/fernandomorse","followers_url":"https://api.github.com/users/fernandomorse/followers","following_url":"https://api.github.com/users/fernandomorse/following{/other_user}","gists_url":"https://api.github.com/users/fernandomorse/gists{/gist_id}","starred_url":"https://api.github.com/users/fernandomorse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fernandomorse/subscriptions","organizations_url":"https://api.github.com/users/fernandomorse/orgs","repos_url":"https://api.github.com/users/fernandomorse/repos","events_url":"https://api.github.com/users/fernandomorse/events{/privacy}","received_events_url":"https://api.github.com/users/fernandomorse/received_events","type":"User","site_admin":false},"created_at":"2018-07-09T20:14:41Z","updated_at":"2018-07-09T20:14:41Z","author_association":"NONE","body":"@pfalcon  @dpgeorge \r\n\r\nThank you, problem fixed"}}
{"actor":{"display_login":"fernandomorse"}}