title: ConnectionResetError: [Errno 104] Connection reset by peer python 3
body: <p>I have a program that queries a REST API (Oanda) and it has been working fine throughout development (about a month or two). The following is how I am requesting my data: </p>
  
  <pre><code>import urllib.request
  def getCandles( currency="EUR_USD", count=500, granularity="D"):
  
      headers = getHeader()
      base_url = 'https://api-fxtrade.oanda.com/'
      ins_url = 'v3/instruments/{}/candles/?count={}&amp;price=M&amp;granularity={}'.format( currency, count, granularity)
      url = base_url + ins_url
      req = urllib.request.Request(url, headers=headers)
      response = urllib.request.urlopen(req)
      response = json.loads( response.decode('utf-8') )
      return response['candles']
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test_indicators.py", line 109, in &lt;module&gt;
      candles = getCandles()
    File "test_indicators.py", line 19, in getCandles
      response = urllib.request.urlopen(url)
    File "/home/adam/anaconda3/lib/python3.6/urllib/request.py", line 223, in urlopen
      return opener.open(url, data, timeout)
    File "/home/adam/anaconda3/lib/python3.6/urllib/request.py", line 526, in open
      response = self._open(req, data)
    File "/home/adam/anaconda3/lib/python3.6/urllib/request.py", line 544, in _open
      '_open', req)
    File "/home/adam/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
      result = func(*args)
    File "/home/adam/anaconda3/lib/python3.6/urllib/request.py", line 1361, in https_open
      context=self._context, check_hostname=self._check_hostname)
    File "/home/adam/anaconda3/lib/python3.6/urllib/request.py", line 1321, in do_open
      r = h.getresponse()
    File "/home/adam/anaconda3/lib/python3.6/http/client.py", line 1331, in getresponse
      response.begin()
    File "/home/adam/anaconda3/lib/python3.6/http/client.py", line 297, in begin
      version, status, reason = self._read_status()
    File "/home/adam/anaconda3/lib/python3.6/http/client.py", line 258, in _read_status
      line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    File "/home/adam/anaconda3/lib/python3.6/socket.py", line 586, in readinto
      return self._sock.recv_into(b)
    File "/home/adam/anaconda3/lib/python3.6/ssl.py", line 1012, in recv_into
      return self.read(nbytes, buffer)
    File "/home/adam/anaconda3/lib/python3.6/ssl.py", line 874, in read
      return self._sslobj.read(len, buffer)
    File "/home/adam/anaconda3/lib/python3.6/ssl.py", line 631, in read
      v = self._sslobj.read(len, buffer)
  ConnectionResetError: [Errno 104] Connection reset by peer
  </code></pre>
  
  <p>I've searched the related questions but couldn't find an answer as a lot of them are using socket module and I am using request. I did seem to get the impression the error was something on my side, however, in writing this question I realized if I query <a href="https://www.oanda.com/account/" rel="nofollow noreferrer">https://www.oanda.com/account/</a> in my search bar I get a 500, so I am assuming that is what is returned to req. Does this mean the site I am querying has blocked me? </p>
  
  <p>I am well under the request limits (1/sec of the 20/sec they allow), but last night I did exceed the limit of number of data points per request until I found 5000 was the maximum. But it worked fine when I ran it this morning. </p>
  
  <p>Also, I am not spoofing my request as a previous SO answer requested and don't feel I need to as it's an API and has been working fine. In addition, I reset my token authorization on Oanda but still no luck. I guess my question is if this sounds like I have been blocked or is this something I can fix on my end or is it possible Oanda server is just down?</p>
  
  <p>If it helps I am using Django 2.0 and python 3 on linux 16.02. </p>
  
  <p>Thanks, and apologies if I didn't follow SO guidelines as this is my first question asked in quite awhile.</p>