Good day! Faced a problem when Django can not see the path to the picture, which is signed in Russian. If the English / numbers, then everything works fine.

Here is a piece of code:

 if callback_data.find('L') != -1: mes = str(user.fish.NameFishRus) bot.send_message(chat_id, mes) try: photo = open('/home/fishbot/fishbot/' + user.fish.Fish_photo.url, 'rb') bot.send_photo(chat_id, photo) except: pass mes = 'Введите длину в сантиметрах:' bot.send_message(chat_id, mes) 

In models, the usual model ImageField I tried this method:

 import urllib.parse if callback_data.find('L') != -1: mes = str(user.fish.NameFishRus) bot.send_message(chat_id, mes) try: photo = open(urllib.parse.quote_plus('/home/fishbot/fishbot/' + user.fish.Fish_photo.url, 'rb')) bot.send_photo(chat_id, photo) except: pass mes = 'Введите длину в сантиметрах:' bot.send_message(chat_id, mes) 

I use Django 1.11 Please help :) Thank you!

  • one
    Probably, problems with the coding. I can not think of a solution to the problem, so I do not see where it lies. I can advise only renaming downloaded files, for example transliteration, or remove a hash from the file name (if I can throw an example of such a code) - virvaldium
  • Why use a url? Use user.fish.Fish_photo.path to get the path to the file on disk. - godva
  • Most likely, it is impossible to correctly substitute url in the path, because the url string is encoded using percent encoding en.wikipedia.org/wiki/Percent-encoding - Chikiro

0