title: How can I fix error: 'expected str, bytes or os.PathLike object, not _io.TextIOWrapper' in Python FTP
body: <p>I have the following code. All this code does is takes a few items from a user's pc then uploads them to a website.</p>
  <pre><code># log in
  session = ftplib.FTP('host', 'username', 'password')
  
  # upload webpage
  try:
      print(Fore.LIGHTMAGENTA_EX + &quot;What's the name of the movie? &quot;, end='')
      print(Fore.WHITE + '', end='')
      name = input('')
      session.cwd(dirname='../video')
      htmlfilecontent = '''&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  
  &lt;head&gt;
      &lt;script async src=&quot;https://www.googletagmanager.com/gtag/js?id=G-4MRZ3QHNFE&quot;&gt;&lt;/script&gt;
      &lt;script&gt;
          window.dataLayer = window.dataLayer || [];
          function gtag() { dataLayer.push(arguments); }
          gtag('js', new Date());
  
          gtag('config', 'G-4MRZ3QHNFE');
      &lt;/script&gt;
      &lt;title&gt;Watching A Movie&lt;/title&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&quot;&gt;
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
      &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.gstatic.com&quot;&gt;
      &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Indie+Flower&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;../css/stylesheet.css&quot;&gt;
      &lt;link rel=&quot;icon&quot; type=&quot;image/png&quot; href=&quot;../logo.png&quot; /&gt;
      &lt;meta name=&quot;description&quot; content=&quot;Watch new movies for free on our platform!&quot; /&gt;
      &lt;meta name=&quot;keywords&quot;
          content=&quot;film, movies, free movies, full movies, Quessts, free full movie, free streaming, online movie&quot; /&gt;
      &lt;meta name=&quot;author&quot; content=&quot;Quessts&quot;&gt;
  &lt;/head&gt;
  
  &lt;body style=&quot;background-color: #303030; font-size: x-large;&quot;&gt;
      &lt;nav class=&quot;navbar navbar-expand-lg navbar-light bg-dark&quot;&gt;
          &lt;div class=&quot;container-fluid&quot;&gt;
              &lt;a href=&quot;../index.html&quot;&gt;
                  &lt;img src=&quot;../logo.png&quot; height=&quot;80px&quot; width=&quot;80px&quot;&gt;
              &lt;/a&gt;
              &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNav&quot;&gt;
                  &lt;ul class=&quot;navbar-nav&quot;&gt;
                      &lt;li class=&quot;nav-item&quot;&gt;
                          &lt;a class=&quot;nav-link active&quot; href=&quot;../index.html&quot;
                              style=&quot;color: aliceblue; margin-left: 20px; margin-right: 20px;&quot;&gt;Home&lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class=&quot;nav-item&quot;&gt;
                          &lt;a class=&quot;nav-link active&quot; href=&quot;../request.html&quot;
                              style=&quot;color: aliceblue; margin-left: 20px; margin-right: 20px;&quot;&gt;Request&lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class=&quot;nav-item &quot;&gt;
                          &lt;a class=&quot;nav-link active&quot; href=&quot;../contact.html&quot;
                              style=&quot;color: aliceblue; margin-left: 20px; margin-right: 20px;&quot;&gt;Contact&lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class=&quot;nav-item&quot;&gt;
                          &lt;a class=&quot;nav-link active&quot; href=&quot;../about.html&quot;
                              style=&quot;color: aliceblue; margin-left: 20px; margin-right: 20px;&quot;&gt;About&lt;/a&gt;
                      &lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/nav&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;br&gt;
  
      &lt;h1 class=&quot;sameline&quot; style=&quot;color: #AA0000;&quot;&gt;''' + name + '''&lt;/h1&gt;
      &lt;br&gt;
      &lt;div class=&quot;sameline&quot;&gt;
  
          &lt;video width=&quot;800&quot; height=&quot;400&quot; controls&gt;
              &lt;source src=&quot;../videosrecords/''' + videoname + '''&quot; type=&quot;video/mp4&quot; /&gt;
          &lt;/video&gt;
      &lt;/div&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;footer class=&quot;site-footer bg-dark&quot;&gt;
          &lt;div class=&quot;container&quot;&gt;
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-sm-12 col-md-6&quot;&gt;
                      &lt;h6&gt;About&lt;/h6&gt;
                      &lt;p class=&quot;text-justify&quot;&gt;AnonFilms is a free video file sharing website dedicated to all users. This
                          website
                          contains movies from all genres and exists for the sole purpose of user entertainment.
                      &lt;/p&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;col-xs-6 col-md-3&quot;&gt;
                      &lt;h6&gt;Legal&lt;/h6&gt;
                      &lt;ul class=&quot;footer-links&quot;&gt;
                          &lt;li&gt;&lt;a href=&quot;../TermsOfService.html&quot;&gt;Terms of service&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href=&quot;../PrivacyPolicy.html&quot;&gt;Privacy Policy&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
  
                  &lt;div class=&quot;col-xs-6 col-md-3&quot;&gt;
                      &lt;h6&gt;Quick Links&lt;/h6&gt;
                      &lt;ul class=&quot;footer-links&quot;&gt;
                          &lt;li&gt;&lt;a href=&quot;../index.html&quot;&gt;Home page&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href=&quot;../request.html&quot;&gt;Request a movie&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href=&quot;../contact.html&quot;&gt;Contact us&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href=&quot;../about.html&quot;&gt;About us&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;hr&gt;
          &lt;/div&gt;
          &lt;div class=&quot;container&quot;&gt;
              &lt;div class=&quot;row&quot;&gt;
                  &lt;div class=&quot;col-md-8 col-sm-6 col-xs-12&quot;&gt;
                      &lt;p class=&quot;copyright-text&quot;&gt;Copyright &amp;copy; 2020 All Rights Reserved by
                          &lt;a href=&quot;../index.html&quot;&gt;AnonFilms&lt;/a&gt;.
                      &lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/footer&gt;
  &lt;/body&gt;
      '''
      realname = name.replace(&quot; &quot;, &quot;&quot;)
  
      htmlfile = open(f'{realname}.html', 'w')
      htmlfile.write(htmlfilecontent)
      htmlfile.close()
      file = open(htmlfile, 'rb')
      session.storbinary(f'STOR {htmlfile}', file)
      print(Fore.GREEN + f&quot;Successfully uploaded '{name}' to website&quot;)
  except Exception as e:
      print(e)
  </code></pre>
  <p>For some reason, after a user enters the name he gets the following error:</p>
  <pre><code>expected str, bytes or os.PathLike object, not _io.TextIOWrapper
  </code></pre>
  <p>It's my first time facing this error. What does it mean? And how can I fix it?
  ......................................................................................................................................................................................................</p>