title: Upload media on Twitter using Tweepy with Python
body: <p>I'm trying to catch a picture from an Url and post it on twitter
  But I got this error that makes me anxious.</p>
  <blockquote>
  <p>TypeError: expected str, bytes or os.PathLike object, not JpegImageFile</p>
  </blockquote>
  <pre><code>from PIL import Image
  import urllib.request
  import tweepy
  
  def get_picture(picture,file_path):
      full_path = file_path + '.jpg'
      urllib.request.urlretrieve(picture,full_path)
  
  
  
  def twitter_api():
      consumer_key = 'XXXXXXXXXXXXXX'
      consumer_secret = 'XXXXXXXXXXXXXX'
      access_token = 'XXXXXXXXXXXXXXXXXXX'
      access_token_secret = 'XXXXXXXXXXXXXXXXXXXXXXX'
      auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
      auth.set_access_token(access_token, access_token_secret)
      api = tweepy.API(auth)
      return api
  
  
  
  picture = (f&quot;https://www.iheartradio.ca/image/policy:1.15731844:1627581512/rick.jpg?f=default&amp;$p$f=20c1bb3&quot;)
  path=r'C:\....\...\....\.......\images\.jpg'
  
  
  text=(&quot;Youpi It works!&quot;)
  
  get_picture(picture,&quot;images/&quot;)
  imageok=picture=Image.open(path)
  twitter_api().update_status_with_media(text,imageok)
  
  </code></pre>
  <p>Will appreciate if anybody got a clue !</p>