python - AttributeError: addinfourl instance has no attribute '__committed' - python

I am trying to read image from url and save it to model. but i am getting this error message:
AttributeError: addinfourl instance has no attribute '__committed'
this is my code:
location = Location()
location.save()
image = urllib.urlopen(img_url)
location.locations_image.create(bild=image)
I guess, i am doing something wrong while reading an image file from url. can someone pls guide me? thanks a lot

Related

'SizedImageInstance' object has no attribute 'open'

I'm attempting to open a thumbnail of an image that was saved with django-versatileimagefield
https://django-versatileimagefield.readthedocs.io/en/latest/
file = instance.image.thumbnail['1920x1080'].open(mode='rb')
I'm getting the following error:
'SizedImageInstance' object has no attribute 'open'
I have success with the following line of code, but I want to open the smaller version as opposed to the original version
file = instance.image.open(mode='rb')
If it helps, the url of the image is instance.image.thumbnail['1920x1080'].url
Thanks!

Attribute Error for Usage of Python Email Import

def ExtractBody(self, msg):
content = ""
if msg.is_multipart():
for payload in msg.get_payload():
content += str(payload.get_payload())
else:
content += str(msg.get_payload())
return content
Hello everyone, with the code above, I was trying to extract the body of a .eml file from a class, but when I used the code above, it gives me the error as shown below.
Why is this so, and how can I fix it?
For extra information, I am getting this email from a web server that makes use of flask.
<class 'AttributeError'>
'bytes' object has no attribute 'read'
EDIT: I have a temporary fix to the problem
I am not sure why, but when I shifted the method from the class to the .py file itself, the code now works.

Python problem with Request AttributeError: module 'request' has no attribute 'get'

Ok, so I have an error and I don't know why. I want to request a bunch of links from a file
while True:
code = file.readline().replace("\n", "")
r = request.get(code)
source = r.post(code)
print(source.text)
input()
Can someone please help me?
import requests at the beggining of the file

Copy and paste in Excel using Python

I try to copy and paste from file to another in Excel with this code:
from win32com import client
xlapp = client.Dispatch("excel.application")
work = xlapp.Workbooks
copysheet = work.Open("D:/mm/trn files/Field Inspection Test Notification for
ERC Review (CI).xlsx" )
cs = copysheet.Worksheets(1)
cs.Visible = 1
cs.Range("B2:G66").Copy()
pastesheet = work.Open("D:/mm/trn files/Field Inspection Test Notification
for ERC Review (ss).xlsx")
pastesheet.Paste(cs.Range("B2:G66"))
But it gives me this error:
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Excel 15.0 Object Library._Workbook instance at 0x47919440>' object has no attribute 'Paste'
And I don't know what's the problem. Do you have any idea?
The pastesheet is a Workbook object, which does not have a Paste method. You might do something similar to what you did with the copysheet object.
i.e.
ps = pastesheet.Worksheets(1)
ps.Paste(cs.Range("B2:G66"))

browser.visit object has no attribute

I am getting an Attribute error on line 8:browser.visit("https://www.facebook.com").
"AttributeError: 'NoneType' object has no attribute 'visit'"
This is my code:
browser = Browser('firefox')
browser.visit('https://www.facebook.com')
browser.find_by_id('email').fill("")
browser.find_by_id('pass').fill("")
browser.find_by_id('loginbutton').first.click()
browser.visit('')
while x != 0:
browser.find_by_css('textarea').fill('')
browser.find_by_id('u_0_1c').click()
It pulled up with a bunch of errors at first but I fixed those, I don't understand this error? If someone could maybe explain why or what is happening it would be much appreciated.
I think you need to have import the Browser package from splinter like this
from splinter import Browser
browser = Browser('firefox)
browser.visit('https://www.facebook.com')

Categories