Okay so I'm programming a Wolfram Alpha API and I added a res string with query and its giving me this error: AttributeError: 'str' object has no attribute 'query'
Here's the PyDa.py:
import PySimpleGUI as sg
sg.theme('Dark Blue')
app_id = ('API_key')
client = (app_id)
layout = [ [sg.Text("Hello, my name's Ted. What's your question?")],
[sg.Input()],
[sg.Button('Ok'), sg.Button('Cancel')] ]
window = sg.Window('Ted', layout)
while True:
event, values = window.read()
if event in (None, 'Cancel'):
break
res = client.query(values[0])
print(next(res.results).text)
window.close()
where values[0] is what the user enters. I've tried completely deleting query and it doesn't work. I thing I need to install something but when I try pip install wolframalpha api it does install but that's not whats missing/ is wrong. I should be getting pods but its not sending those because of the error.
Hmm, I don't know exactly what happens before the client.query call, but the AtrributeError says client is of type str. I don't think there is a problem with dependencies, because then the error would be different. The client is according to the docs defined with client = Client(getfixture('API_key')). If you have this in your code, then I have no idea what's wrong.
Related
I am currently writing a web-application and need to "refresh the page" by clearing the cache. So the user should be able to refresh the page. For this reason I created a button with the following statement in it st.legacy_caching.caching.clear_cache(). However, even I have the most updated version (1.12.0) I get the following error "module 'streamlit' has no attribute 'legacy_caching'"
my code looks like this
#st.cache(allow_output_mutation=True, suppress_st_warning=True)
def load_General():
engine = sa.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
con=engine.connect()
general_query_raw='''string'''
General_raw=pd.read_sql(general_query_raw,con)
general_query_cleansed='''string'''
General_cleansed=pd.read_sql(general_query_cleansed,con)
return General_raw, General_cleansed
#st.cache(allow_output_mutation=True,suppress_st_warning=True)
def load_Role():
engine = sa.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
con=engine.connect()
role_query_raw='''string'''
Role_raw=pd.read_sql(role_query_raw,con)
role_query_cleansed='''string'''
Role_cleansed=pd.read_sql(role_query_cleansed,con)
return Role_raw,Role_cleansed
With the following line(s) I try to clean the cache in order to be able to get the latest data from the DB
def clear_cache():
st.legacy_caching.caching.clear_cache()
st.sidebar.button("Refresh Program",on_click=clear_cache)
Any Idea what could help me here?
I had come across a similar issue recently, instead of creating a button to clear the cache you can use the st.empty() function that should clear the cache.
Just call as below before calling your defined functions:
load_general = st.empty()
load_role = st.empty()
load_general = load_General()
load_role = load_Role()
https://docs.streamlit.io/library/api-reference/layout/st.empty
My task is to call a function with photoshop through a telegram bot. To do this, I take user information from the telegram chat for the program (for example, some text to change it inside the psd), but when I call this function, my code gives the error "Please check if you have Photoshop installed correctly.", BUT if call the same function not through the bot, then everything works fine. What could be the problem?
What I already tried - reinstall photoshop, install newer version of photoshop, add path in windows environment variables. Running through pywin32 is not profitable for me.
here I take and send the argument to the function
#bot.message_handler(content_types=['text'])
def func(message):
if(message.text == '/ph'):
user_info = {'test' : 'exampletext'}
test_edit_text(user_info)
here is a function, it just changes the text
def test_edit_text(info_from):
try:
psApp = ps.Application()
psApp.Open(r"mypath\first.psd")
doc = psApp.Application.ActiveDocument
print(info_from['test'])
text_from_user = info_from['test']
layer1init = doc.ArtLayers["layer1"]
text_new_layer1 = layer1init.TextItem
text_new_layer1 .contents = f"{text_from_user .upper()}"
options = ps.JPEGSaveOptions(quality=5)
jpg = r'mypath\photo.jpg'
doc.saveAs(jpg, options, True)
except Exception as e:
print(e)
if we call the "test_edit_text()" function separately, not through the bot, everything will work
When i use below pywinauto code, i am getting error saying
from pywinauto.controls.win32_controls import ButtonWrapper
checkbox = ButtonWrapper(app.Dialog.child_window(title='Has Balance',auto_id='HasBalanceCheckEdit',control_type='CheckBox').TCheckBox.WrapperObject())
print(checkbox.GetCheckState())
Error:
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'TCheckBox' in 'dict_keys(['Has Balance', 'Has BalanceStatic', 'Static'])'
Based on the output you provided, next level spec TCheckBox is not needed. Just use this code:
checkbox = app.Dialog.child_window(title='Has Balance', auto_id='HasBalanceCheckEdit', control_type='CheckBox').wrapper_object()
Explicit ButtonWrapper instantiation is also not necessary because the control type is already auto detected by .wrapper_object(). That's why control_type='CheckBox' in your child_window can find the control.
used import pywinauto.controls.uia_controls to resolve the above code.
I'm trying to create a Reddit scraper that takes the first 100 pages from the Reddit home page and stores them into MongoDB. I keep getting the error:
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
Here is my code
import pymongo
import praw
import time
def main():
fpid = os.fork()
if fpid!=0:
# Running as daemon now. PID is fpid
sys.exit(0)
user_agent = ("Python Scraper by djames v0.1")
r = praw.Reddit(user_agent = user_agent) #Reddit API requires user agent
conn=pymongo.MongoClient()
db = conn.reddit
threads = db.threads
while 1==1: #Runs in an infinite loop, loop repeats every 30 seconds
frontpage_pull = r.get_front_page(limit=100) #get first 100 posts from reddit.com
for posts in frontpage_pull: #repeats for each of the 100 posts pulled
data = {}
data['title'] = posts.title
data['text'] = posts.selftext
threads.insert_one(data)
time.sleep(30)
if __name__ == "__main__":
main()
insert_one() was not added to pymongo until version 3.0. If you try calling it on a version before that, you will get the error you are seeing.
To check you version of pymongo, open up a python interpreter and enter:
import pymongo
pymongo.version
The legacy way of inserting documents with pymongo is just with Collection.insert(). So in your case you can change your insert line to:
threads.insert(data)
For more info, see pymongo 2.8 documentation
I have been trying to enable ELB connection draining using the modify_lb_attribute method in the python boto module; however I haven't been able to get it working. According to the documentation here http://boto.readthedocs.org/en/latest/ref/elb.html I should be able to call it like his:
modify_lb_attribute(load_balancer_name, attribute, value)
Here is an example:
modify_lb_attribute('my-elb', 'connectionDraining', 120)
When I do this however I receive the following error:
File "/Library/Python/2.7/site-packages/boto/ec2/elb/init.py", line 421, in modify_lb_attribute
value.enabled and 'true' or 'false'
AttributeError: 'NoneType' object has no attribute 'enabled'
I have been able to get it to work successfully with crossZoneLoadBalancing.
For example this works:
modify_lb_attribute('my-elb', 'crossZoneLoadBalancing', 'true')
Any help or suggestions would be appreciated.
Thanks
Working syntax for instantiating a ConnectionDrainingAttribute and passing it a to a load balancer:
from boto.ec2.elb.attributes import ConnectionDrainingAttribute
import boto.ec2.elb
connection = boto.ec2.elb.connect_to_region("region")
cda = ConnectionDrainingAttribute(connection)
cda.enabled = True
cda.timeout = 120
connection.modify_lb_attribute(
load_balancer_name='my-elb',
attribute='connectionDraining',
value=cda
)
More information about the ConnectionDrainingAttribute class can be found here in the boto docs.
When you modify the connectionDraining attribute of a load balancer, there are actually two values you can supply. The first is a boolean indicating whether you are enabling or disabling the connection draining feature. The second is an integer indicating the timeout which obviously applies only if connection draining is being enabled.
To allow you to specify both of these values, boto defines a ConnectionDrainingAttribute class in boto.ec2.elb.attributes. You must pass an instance of this class as the value to modify_elb_attribute, e.g.:
from boto.ec2.elb.attributes import ConnectionDrainingAttribute
cda = ConnectionDrainingAttribute()
cda.enabled = True
cda.timeout = 120
...
modify_lb_attribute('my-elb', cda)