2016-04-11 18 views
1

Bu hata başlamıştı: io.UnsupoortedOperation: bazı değişiklikler yaptım okuyun. Bu satırı img = Image.open(f)img = Image.open(f, "rb") olarak değiştirdikten sonra Bu hatayı alıyorum: ValueError: hatalı mod 'rb' Burada sorun nedir? Bunu nasıl düzeltirim?Django hatası: io.UnsupportedOperation: okumak ve ValueError: Kötü mod 'rb'

class LinkCreateView(CreateView): 
    model = Link 
    form_class = LinkForm 

    def form_valid(self, form): 
     hash = str(uuid.uuid1()) 
     with open("tmp_img_original_{}.png".format(hash), "wb") as f: 
      res = requests.get(form.instance.url, stream=True) 
      if not res.ok: raise Exception("URL'de dosya yok: 404") 
      for block in res.iter_content(1024): f.write(block) 

      img = Image.open(f, "rb") 
      width, height = img.size 
      img.thumbnail(get_size(width, height), Image.ANTIALIAS) 
      img.save() 

      djfile = File(f) 

      form.img.save("img_tn_{}.png".format(hash), djfile, save=True) 
      f.close() 

     f = form.save(commit=False) 
     f.rank_score = 0.0 
     f.submitter = self.request.user 
     f.save() 

     return super(CreateView, self).form_valid(form) 

cevap

0

views.py yanıt modu ile dosya "wb +"

Değişim açık olan bu

with open("tmp_img_original_{}.png".format(hash), "wb") as f: 

with open("tmp_img_original_{}.png".format(hash), "wb+") as f: 
için
İlgili konular