The github link for the code is given below:
https://github.com/AlchemyAPI/alchemyapi-recipes-twitter
I get the following error when I run recipe.py:
Traceback (most recent call last):
File "recipe.py", line 340, in <module>
main(sys.argv[1], int(sys.argv[2]))
File "recipe.py", line 43, in main
print_results()
File "recipe.py", line 303, in print_results
avg_pos_score = mean_results['result'][2]['avgScore']
TypeError: 'CommandCursor' object has no attribute '__getitem__'
I am using python version 2.7.6
Please do help me out to solve this.
Yeah, I finally got the correct output.Thanks to Games Brainiac for helping me to figure it out.
mean_results = list(tweets.aggregate([{"$group" : {"_id": "$sentiment",
"avgScore" : { "$avg" : "$score"}}}]))
avg_pos_score = mean_results[1]['avgScore']
avg_neg_score = mean_results[0]['avgScore']
The mean_results will contain a list of dictionary entities(in this case 3 entities-neg,pos,neutral).
So mean_results[0] refers to the negative entity.
mean_results[1] refers to the positive entity.
and so on.
mean_results[1]['avgScore]=avg score of the positive entity.
and so on...
I think you need to change line 301 to 304 to reflect the new changes in the API.
Firstly, change this line:
mean_results = tweets.aggregate([{"$group" : {"_id": "$sentiment", "avgScore" : { "$avg" : "$score"}}}])
to
mean_results = list(tweets.agg....)
So now, you no longer need to use the result for the CommandCursor.
Instead, what you have to do is this:
list(mean_results[2]['avgScore'])
Instead, and repeat with the next line too. Just remove the result part.
Related
I have a script I found here:
https://n2ws.com/wp-content/uploads/2017/10/ebs-report.py
Running it returns the below error:
Traceback (most recent call last):
File "ebs-report.py", line 194, in <module>
retval = create_ebs_report (args.regions, args.access_key, args.secret_key, args.file)
File "ebs-report.py", line 130, in create_ebs_report
'type' : volume_types_map[vol.type],
KeyError: u'st1'
There is no mapping for st1 (which is a type of volume from aws that perhaps didn't exist when the script was written) so I am trying to resolve this.
I am hoping that the error can be resolved by adding that extra volume type so change the script here:
volume_types_map = { u'standard' : u'Standard/Magnetic', u'io1' : u'Provisioned IOPS (SSD)', u'gp2' : u'General Purpose SSD'}
To this...
volume_types_map = { u'standard' : u'Standard/Magnetic', u'io1' : u'Provisioned IOPS (SSD)', u'gp2' : u'General Purpose SSD', u'Throughput Optimized HDD', u'st1'}
So basically I am adding the st1 part on to the mapping in the hope that it sorts out the issue.
This results in an error. I must have got the syntax wrong within the extra value that I added to the "volume_types_map"...
File "ebs-report2.py", line 102
volume_types_map = { u'standard' : u'Standard/Magnetic', u'io1' : u'Provisioned IOPS (SSD)', u'gp2' : u'General Purpose SSD', u'Throughput Optimized HDD', u'st1'}
^
SyntaxError: invalid syntax
This is the error that results from my change, above.
Can anyone help with what I seem to have incorrectly added and identify where I may have gone wrong, I suspect with the commas colons and spaces.
You should add the st1 (Throughput Optimized) type to the script so it gets recognized
volume_types_map = {u'standard': u'Standard/Magnetic', u'io1':
u'Provisioned IOPS (SSD)', u'gp2': u'General Purpose SSD', u'st1':
u'Throughput Optimized HDD'}
I am trying to get the list of assignments due/coursework for all the courses using the Google Classroom API. I am getting a list of courses using the below code :
results = service.courses().list(pageSize = 10).execute()
courses = results.get('courses',[])
Once I get the list of all the courses, I loop over each the course and try to supply the courseID in order to get the list of coursework using courses.courseWork.list method, but I'm getting an error.
I have written the following code :
for course in courses :
print(course['name'])
print "Assignments you have due in this course : "
print course[u'id']
course_work_results = service.courses().courseWork().list().execute()
print course_work_results
Since I am not supplying the courseID anywhere (which I need to know how to do), I get the following error :
Traceback (most recent call last):
File "classroom.py", line 53, in <module>
course_work_results = service.courses().courseWork().list().execute()
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py", line 727, in method
raise TypeError('Missing required parameter "%s"' % name)
TypeError: Missing required parameter "courseId"
The error is caused due to the line
course_work_results = service.courses().courseWork().list().execute()
How to fix this ?
I have seen a lot of KeyCount Errors online but none of them quite match the troubles that I'm having. I am using feed parser to try and create a one run application that accesses all the URLs in a text file and outputs all the entries in each URL. When I run this code :
import feedparser as f
with open('addresses.rtf', 'r') as addresses:
for line in addresses:
d = f.parse(line)
print d["feed"]["title"]
print ""
print d.feed.subtitle
print ""
for post in d.entries:
print post.title
print post.link
print ""
I get this error message :
Traceback (most recent call last):
File "/Users/Josh/Desktop/Feed Parser Python Project/init.py", line 7, in <module>
print d["feed"]["title"]
File "build/bdist.macosx-10.6-intel/egg/feedparser.py", line 375, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'title'
My text file is just a .rtf file that has a URL on each line (3 lines).
If someone could give us a hand please let me know and if you need any extra info please don't hesitate to ask. Any help is welcome. Thank you!
It's hard to tell exactly what is wrong here, but in the general case, any KeyError is because the data you are trying to access is not exactly what you expected. It's best to throw your assumptions out the window and take a close look at the actual data that your code is working with.
For debugging, I would recommend taking a close look at what happens before the error. What is the value of line as you read the file? Is it correct? What is the value of d? Did the call to f.parse(line) result in a valid object?
I have a custom field named "Status" with an id of 10100 which is a select list with optional values of "One", "Two", "Three" and "Four". Default value is "One".
I am writing a JIRA python script to update the value of this field conditionally. Say if the existing value is "One", it should be changed to "Two".
This is my code.
from jira.client import JIRA
jira_options={'server': 'http://localhost:8080'}
jira=JIRA(options=jira_options,basic_auth=('usrname','pwd'))
for issue in jira.search_issues(' cf[10100] = "One" '):
issue.update(fields={'customfield_10100': 'Two'})
It's giving me the following error.
Traceback (most recent call last):
File "test.py", line 11, in <module>
issue.update(fields={'customfield_10100': 'Two'})
File "C:\Python27\lib\site-packages\jira\resources.py", line 193, in update
super(Issue, self).update(**data)
File "C:\Python27\lib\site-packages\jira\resources.py", line 72, in update
raise_on_error(r)
File "C:\Python27\lib\site-packages\jira\exceptions.py", line 29, in raise_on_
error
error = errorMessages[0]
IndexError: list index out of range
Could you please tell me what might be wrong?
I had used the same syntax for editing a custom field of type text field and it had worked fine.
Try it like this:
issue.update(fields={'customfield_10100': {'value':'Two'}})
or like this:
issue.update(fields={'customfield_10100': {'value','Two'}})
I am not sure which one will work out for you because I never worked with Python, but one of them should work.
Hey guys, I am a little lost on how to get the auth token. Here is the code I am using on the return from authorizing my app:
client = gdata.service.GDataService()
gdata.alt.appengine.run_on_appengine(client)
sessionToken = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
client.UpgradeToSessionToken(sessionToken)
logging.info(client.GetAuthSubToken())
what gets logged is "None" so that does seem right :-(
if I use this:
temp = client.upgrade_to_session_token(sessionToken)
logging.info(dump(temp))
I get this:
{'scopes': ['http://www.google.com/calendar/feeds/'], 'auth_header': 'AuthSub token=CNKe7drpFRDzp8uVARjD-s-wAg'}
so I can see that I am getting a AuthSub Token and I guess I could just parse that and grab the token but that doesn't seem like the way things should work.
If I try to use AuthSubTokenInfo I get this:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 507, in __call__
handler.get(*groups)
File "controllers/indexController.py", line 47, in get
logging.info(client.AuthSubTokenInfo())
File "/Users/matthusby/Dropbox/appengine/projects/FBCal/gdata/service.py", line 938, in AuthSubTokenInfo
token = self.token_store.find_token(scopes[0])
TypeError: 'NoneType' object is unsubscriptable
so it looks like my token_store is not getting filled in correctly, is that something I should be doing?
Also I am using gdata 2.0.9
Thanks
Matt
To answer my own question:
When you get the Token just call:
client.token_store.add_token(sessionToken)
and App Engine will store it in a new entity type for you. Then when making calls to the calendar service just dont set the authsubtoken as it will take care of that for you also.