title: Python: FancyURLopener fails on second loop, ValueError: read of closed file
body: <p>\Anaconda3\lib\tempfile.py", line 483, in func_wrapper
      return func(*args, **kwargs)
  ValueError: read of closed file</p>
  
  <p>I don't know if this is the issue even I can't figure this out. This is being called in a loop and the first loops works fine but errors on the second loop. Reading the file it says </p>
  
  <p>"This class provides a wrapper around files opened for
      temporary use.  In particular, it seeks to automatically
      remove the file when it is no longer needed."</p>
  
  <p>But it is still needed and closing anyway, causing the error. This is my best guess.</p>
  
  <p>I'm using this because a normal request is blocked by the server. Which by the way, a normal request loops and works fine (tested unblocked links). This one works on the first cycle then fails on the second. I think because the "link" variable is being reused.</p>
  
  <pre><code>  class AppURLopener(urllib.request.FancyURLopener):
        version = "Mozilla/5.0"
  </code></pre>
  
  <p>looping part</p>
  
  <pre><code>  opener = AppURLopener()
    linkSource = opener.open(link).read() #error on this line "read of closed file (second run through)"
  </code></pre>
  
  <p>I tried to modify the code so that the "link" variable is different which I'm guessing would solve it but the only way I could find to do that was make it a list or a dictionary. Both of those don't work because the base variable is still closed I guess.</p>
  
  <p>In that case I tried using open() at the start of the loop which produces an error like this "TypeError: expected str, bytes or os.PathLike object, not dict"</p>
  
  <p>If I just have it be a normal string it doesn't work either which on another point doesn't make sense because above it says "expected str", I assumed if it was just a normal str it would work but it just produces another error "OSError: [Errno 22] Invalid argument: <a href="http://www.link.com" rel="nofollow noreferrer">http://www.link.com</a>"</p>
  
  <p>I guess random variables can't be used with open() like that. So why is it closed? Or is something else closed?</p>
  
  <p>I don't know.</p>