Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to automate an emailing process at work and got everything working down to the final line.
Here is the issue confined to its own test script to ensure the error is not something else:
import win32com.client as win32
outlook = win32.Dispatch("Outlook.application")
addresses = ["email1", "email2"]
for address in addresses:
email = outlook.CreateItem(0)
email.To = address
email.Subject = "Attendance"
email.Body = " - "
email.send()
The email will send to the first email address if valid, but not the second.
Here is the error:
Traceback (most recent call last):
File "C:\Users\jbruce\OneDrive - Stirling Skills Training\Reporting\EST\Auto attendance\Test.py", line 12, in <module>
email.send()
TypeError: 'bool' object is not callable
I am mainly puzzled about why the script will run one step of the for loop, but not the other.
Thanks for your help in advance.
You're looking for:
email.Send()
The issue here is that:
email.send
is, in fact, a Bool.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am attempting to use the following script in twilio to create a chatbot.
However if the message sent to the chatbot contains keywords from the CChangDict then it works fine. If the message contains words from the SLoansDict then it prompts an error 5000. This I believe is down the my incorrect useage of the "for" loop.
Any ideas on how I can improve my code to make sure that if a message contains words from either dictionary ( CChangeDict or SLoansDict ) that the correct answer is sent in response?
Thanks!
def respond(message):
response = MessagingResponse()
response.message(message)
return str(response)
#app.route('/webhook', methods=['POST'])
def webhook():
student = request.form.get('From')
message = request.form.get('Body').lower()
for keyword in CChangeDict:
if keyword in message:
return respond(JoeDict["ClimateChange"])
for keywork in SLoansDict:
if keyword in message:
return respond(JoeDict["StudentLoans"])
You have a typo in the second for loop – keywork should be keyword.
You're getting error 500 because you aren't responding anything in the case where the keyword isn't found.
All in all,
for keyword in CChangeDict:
if keyword in message:
return respond(JoeDict["ClimateChange"])
for keyword in SLoansDict:
if keyword in message:
return respond(JoeDict["StudentLoans"])
return respond("I don't know what to say.")
or to coalesce the two for loops,
for keywords, response in (
(CChangeDict, JoeDict["ClimateChange"]),
(SLoansDict, JoeDict["StudentLoans"]),
):
if any(keyword in message for keyword in keywords):
return respond(response)
return respond("I don't know what to say.")
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm studying Flask very recently and trying to create API.
However, when It request json data, this error occurs.
if content['words'] is not None:
TypeError: 'NoneType' object is not subscriptable
could anyone can help this?
Thanks
my code is below:
#app.route("/process",methods=['GET', 'POST'])
def process():
content = request.json
words = {}
if content['words'] is not None:
for data in content['words'].values():
words[data['word']] = data['weight']
process_from_text(content['text'], content['maxCount'], content['minLength'], words)
result = {'result':True}
return jsonify(result
The problem is most likely that request is not a valid json request. If that is the case then content will be equal to None which means it is not subscriptable.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have the following list of tuples in Python.
CHECKS = [
('Standard JavaScript Inlining Optimization', ('EMBED_JAVASCRIPT',), 'check_js_inlining'),
('HTML5 Advanced Cache', ('JAVASCRIPT_HTML5_CACHE', 'CSS_HTML5_CACHE'), 'check_html5_advanced_cache'),
('Cookieless Resource Domain', ('RENAME_JAVASCRIPT', 'RENAME_CSS'), 'check_cookieless_resource_domain'),
('Minificatiopn of JS', ('MINIFY_JAVASCRIPT',), 'check_js_minifaction'),
('File Versioning', ('RENAME_JAVASCRIPT', 'RENAME_IMAGE', 'RENAME_CSS'), 'check_file_versioning'),
('Small Image Embedding', ('EMBED_IMAGE',), 'check_small_image_embedding'),
('Responsive Image Loading', ('RESPONSIVE_IMAGES',), 'check_responsive_image_loading')
('Asynchronous JS and CSS Loading', ('ASYNC_JAVASCRIPT',), 'check_async_js_and_css_loading'),
('JS Pre-Execution', ('PRE_EXECUTE_JAVASCRIPT',), 'check_js_pre_execution'),
]
Upon execution it throws the error
File "FEO_processor.py", line 14, in FEOProcessor
('Asynchronous JS and CSS Loading', ('ASYNC_JAVASCRIPT',), 'check_async_js_and_css_loading'),
TypeError: 'tuple' object is not callable
What am I missing here.
You are missing a comma:
('...', ('RESPONSIVE_IMAGES',), 'check_responsive_image_loading')
↑ HERE
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am kinda new to working with json and python and I am stuck on the parsing the data in js to generate an expression. I would really appreciate anyone suggestions on the best path to take.
Here is the Data I am working with
{"statuses":[{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Dec 06 15:06:44 +0000 2013","id":408975801577926656,"id_str":"408975801577926656","text":"RT #jk636575: #GhanaNudes contact me if you want to swing\njk636575#gmail.com","user":{"id":974873810,"id_str":"974873810","name":"Gh Nudes","screen_name":"GhanaNudes","location"
Here is my code:
def main():
ts = TwitterSearch()
response, data = ts.search('#gmail.com', result_type='recent')
js = json.loads(data)
messages = ([data_items] for msg in js)
I need to parse the content in js and turn it into a generator expression so that I only write: Created_at , text , user:{is
Based on the Twitter search API docs,
messages = ([msg['created_at'], msg['txt'], msg['user']['id']] for msg in js['statuses'])
Note that I have updated my answer to the original question to include this.
Edit: It might be a bit safer to replace in js['statuses'] with in js.get('statuses', []).
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to read a huge file lazily in with the pandas get_csv function. I want to access the first 5000 elements of a specified column. But I am getting the error I mentioned in my title.
#fetching data
train = pd.read_csv(os.path.join(dir,"Train.csv"),iterator = True)
test = pd.read_csv(os.path.join(dir,"Test.csv"),iterator = True)
Getting the parts of the data I need:
labels = np.array(train.get_chunk(5000))[:,3]
train = np.array(train.get_chunck(5000))[:,2]
test = np.array(test.get_chunk(5000))[:,2]
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-43-b164e8752510> in <module>()
1 labels = np.array(train.get_chunk(5000))[:,3]
----> 2 train = np.array(train.get_chunck(5000))[:,2]
3 test = np.array(test.get_chunk(5000))[:,2]
AttributeError: 'TextFileReader' object has no attribute 'get_chunck'
Apparently I am not allowed to do it like this? If not, how could I rewrite this to achieve what I am trying to achieve with this code?
get_chunck is a spelling error!
Try get_chunk instead of get_chunck.
get_chunck is the culprit ! get_chunk