Why do I get AttributeError: Canvas has no attribute acroForm? - python

I am trying to create a PDF with an interactive form, using Reportlab. I followed several tutorials but I am always getting the same error. The line form = c.acroForm produces AttributeError: 'Canvas' object has no attribute 'acroForm'
Has anyone experienced the same problem and know how to solve it?
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfform
c = canvas.Canvas('my_form.pdf')
form = c.acroForm
c.save()

Related

Error while removing classes in owlreaddy

I tried removing a class from my Ontology in owlready and im having an error :
File "C:\Users\ramid\AppData\Local\Programs\Python\Python37\lib\site-packages\owlready2\namespace.py", line 274, in _to_python
if o < 0: return self._parse_bnode(o)
TypeError: '<' not supported between instances of 'NoneType' and 'int'
My code is :
import os
from owlready2 import *
onto = get_ontology("test.owl").load()
classes_to_delete=[]
a1 = get_namespace("http://w3id.org/gbo#")
a2 = get_namespace("http://www.ontology-of-units-of-measure.org/resource/om-2/")
with onto:
destroy_entity(a1.component)
Im thinking of changing to owlapi because of this inconvience . But im sure there a way to fix this because owlready is known to be stable and not have such problems. So does anyone have another way to do this or a reason why there is such an error?

How i can solve this problem in Python code (TKinter, Pillow, customtkinter)

I'm trying to add an image to Customtkinter Buttom, but an error occurs
import sqlite3
from tkinter import \*
import customtkinter
from tkinter import ttk
from PIL import Image, ImageTk
customtkinter.set_appearance_mode('dark')
customtkinter.set_default_color_theme('blue')
\#Create a Ctk instance(app)
main = customtkinter.CTk()
main.geometry("400x240")
main.resizable(width=False, height=False)
\#Username Frame
username_tittle = customtkinter.CTkLabel(master=main, text='Username:').place(relx=0.2, rely= 0.3)
username_box = customtkinter.CTkEntry(master=main, width=150)
username_box.place(relx=0.43, rely=0.3)
python_image = ImageTk.PhotoImage(Image.open('user_icon.png'), Image.ANTIALIAS, )
but = customtkinter.CTkButton(master=main, image=python_image).pack()
this code generate the following error:
c:\\Users\\claud\\OneDrive\\Documentos\\meuusprojetos\\Login\\main.py:19: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use LANCZOS or Resampling.LANCZOS instead.
python_image = ImageTk.PhotoImage(Image.open('user_icon.png'), Image.ANTIALIAS, )
CTkButton Warning: Given image is not CTkImage but \<class 'PIL.ImageTk.PhotoImage'\>. Image can not be scaled on HighDPI displays, use CTkImage instead.
Traceback (most recent call last):
File "c:\\Users\\claud\\OneDrive\\Documentos\\meuusprojetos\\Login\\main.py", line 20, in \<module\>
but = customtkinter.CTkButton(master=main, image=python_image).pack()
File "C:\\Users\\claud\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\customtkinter\\windows\\widgets\\ctk_button.py", line 106, in __init__
self.\_draw()
File "C:\\Users\\claud\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\customtkinter\\windows\\widgets\\ctk_button.py", line 243, in \_draw
self.\_update_image() # set image
File "C:\\Users\\claud\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\customtkinter\\windows\\widgets\\ctk_button.py", line 154, in \_update_image
self.\_image_label.configure(image=self.\_image.create_scaled_photo_image(self.\_get_widget_scaling(),
AttributeError: 'PhotoImage' object has no attribute 'create_scaled_photo_image'
Can anybody help me?
It looks like you are encountering an error when trying to add an image to a CTkButton widget in the customtkinter module.
The error message mentions that the given image is not a CTkImage, but a PIL.ImageTk.PhotoImage.
To fix this issue, you can try the following:
Use the CTkImage class to create an image object instead of the PIL.ImageTk.PhotoImage class. You can do this by using the CTkImage.open() method to open the image file, like this:
python_image = customtkinter.CTkImage.open('user_icon.png')
I hope this suggestion will help you.
Latest version of customtkinter accepts CTkImage only for image option of its widgets:
...
python_image = customtkinter.CTkImage(Image.open("user_icon.png"))
customtkinter.CTkButton(master=main, image=python_image).pack()
...

AttributeError: 'function' object has no attribute 'text'

Do you know repl.it?
I am coding python on this site.
And my goal is creating Web Scraper.
I think this code is clean.
But I'm getting an error:
AttributeError: 'function' object has no attribute 'text'
My code:
import requests
indeed_result = requests.get
("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
print(indeed_result.text)
Surely, I have requests package installed.
Please give me some advice
You just need to remove the back to new line after get like this:
import requests
indeed_result = requests.get("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
print(indeed_result.text)
if you want to continue typping in the next line just add a backslash \ as follows:
indeed_result = requests.get\
("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
Removing back to new line after get
try this
import requests
res = requests.get("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
print(res.text)
# result if success 200

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')

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

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

Categories