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.
Related
I am taking cs50 class. Currently on Week 7.
Prior to this coding, python was working perfectly fine.
Now, I am using SQL command within python file on VS Code.
cs50 module is working fine through venv.
When I execute python file, I should be asked "Title: " so that I can type any titles to see the outcome.
I should be getting an output of the counter, which tracks the number of occurrence of the title from user input.
import csv
from cs50 import SQL
db = SQL("C:\\Users\\wf user\\Desktop\\CODING\\CS50\\shows.db")
title = input("Title: ").strip()
#uses SQL command to return the number of occurrence of the title the user typed.
rows = db.execute("SELECT COUNT(*) AS counter FROM shows WHERE title LIKE ?", title) #? is for title.
#db.execute always returns a list of rows even if it's just one row.
#setting row to the keyword which is is rows[0]. the actual value is in rows[1]
row = rows[0]
#passing the key called counter will print out the value that is in rows[1]
print(row["counter"])
I have shows.db in the path.
But the output is printing "Found". It's not even asking for a Title to input.
PS C:\Users\wf user\Desktop\CODING\CS50> python favoritesS.py
Found
I am expecting the program to ask me "Title: " for me, but instead it's print "Found"
In cs50, the professor encountered the same problem when he was coding phonebook.py, but the way he solved the problem was he put the python file into a separate folder called "tmp"
I tried the same way but then I was given a long error message
PS C:\Users\wf user\Desktop\CODING\CS50> cd tmp
PS C:\Users\wf user\Desktop\CODING\CS50\tmp> python favoritesS.py
Traceback (most recent call last):
File "C:\Users\wf user\Desktop\CODING\CS50\tmp\favoritesS.py", line 5, in <module>
db = SQL("C:\\Users\\wf user\\Desktop\\CODING\\CS50\\shows.db")
File "C:\Users\wf user\AppData\Local\Programs\Python\Python311\Lib\site-packages\cs50\sql.py", line 74, in __init__
self._engine = sqlalchemy.create_engine(url, **kwargs).execution_options(autocommit=False, isolation_level="AUTOCOMMIT")
File "<string>", line 2, in create_engine
File "C:\Users\wf user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\util\deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "C:\Users\wf user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\create.py", line 518, in create_engine
u = _url.make_url(url)
File "C:\Users\wf user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\url.py", line 732, in make_url
return _parse_url(name_or_url)
File "C:\Users\wf user\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\url.py", line 793, in _parse_url
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Could not parse SQLAlchemy URL from string 'C:\Users\wf user\Desktop\CODING\CS50\shows.db'
Here is the proof that the code I posted is the same code I am working on.
I use Start Debugging under Run menu on VSCode and it's working! But not when I don't use debugging.
Is this the library you are using? https://cs50.readthedocs.io/
It may be that one of your intermediate results is not doing what you think it is. I would recommend you put print() statements at every step of the way to see the values of the intermediate variables.
If you have learned how to use a debugger, that is even better.
So I have tried to write a small config file for my script, which should specify an IP address, a port and a URL which should be created via interpolation using the former two variables. My config.ini looks like this:
[Client]
recv_url : http://%(recv_host):%(recv_port)/rpm_list/api/
recv_host = 172.28.128.5
recv_port = 5000
column_list = Name,Version,Build_Date,Host,Release,Architecture,Install_Date,Group,Size,License,Signature,Source_RPM,Build_Host,Relocations,Packager,Vendor,URL,Summary
In my script I parse this config file as follows:
config = SafeConfigParser()
config.read('config.ini')
column_list = config.get('Client', 'column_list').split(',')
URL = config.get('Client', 'recv_url')
If I run my script, this results in:
Traceback (most recent call last):
File "server_side_agent.py", line 56, in <module>
URL = config.get('Client', 'recv_url')
File "/usr/lib64/python2.7/ConfigParser.py", line 623, in get
return self._interpolate(section, option, value, d)
File "/usr/lib64/python2.7/ConfigParser.py", line 691, in _interpolate
self._interpolate_some(option, L, rawval, section, vars, 1)
File "/usr/lib64/python2.7/ConfigParser.py", line 716, in _interpolate_some
"bad interpolation variable reference %r" % rest)
ConfigParser.InterpolationSyntaxError: bad interpolation variable reference '%(recv_host):%(recv_port)/rpm_list/api/'
I have tried debugging, which resulted in giving me one more line of error code:
...
ConfigParser.InterpolationSyntaxError: bad interpolation variable reference '%(recv_host):%(recv_port)/rpm_list/api/'
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x7fc4d32c46e0> ignored
Here I am stuck. I don't know where this _remove function is supposed to be... I tried searching for what the message is supposed to tell me, but quite frankly I have no idea. So...
Is there something wrong with my code?
What does '< function _remove at ... >' mean?
There was indeed a mistake in my config.ini file. I did not regard the s at the end of %(...)s as a necessary syntax element. I suppose it refers to "string" but I couldn't really confirm this.
My .ini file for starting the Python Pyramid server had a similar problem.
And to use the variable from the .env file, I needed to add the following: %%(VARIEBLE_FOR_EXAMPLE)s
But I got other problems, and I solved them with this: How can I use a system environment variable inside a pyramid ini file?
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 ?
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.
As stated in this question:
lxml preserves attributes order?
And taking the #abarnet suggestion I wrote the following line of code:
root = ET.Element('{%s}Catalogo' % SATNS, OrderedDict([("Ano","2014"),("Mes","02"),("TotalCtas","219"),("RFC","XXX010101XXX"),("Version","1.0")]), nsmap={'catalogocuentas':SATNS})
I get this:
<catalogocuentas:Catalogo xmlns:catalogocuentas="http://www.sat.gob.mx/catalogocuentas" Ano="2014" Mes="02" TotalCtas="219" RFC="XXX010101XXX" Version="1.0"/>
which is great(it preserves the desired order), but when I want to add the missing information:
xmlns:xsi="link_2" xsi:schemaLocation="http://www.sat.gob.mx/catalogocuentas"
as part of my xml and then I add this info in my python code:
attrib={location_attribute: 'http://www.sat.gob.mx/catalogocuentas'}
so that it becomes:
root = ET.Element('{%s}Catalogo' % SATNS, OrderedDict([("Ano","2014"),("Mes","02"),("TotalCtas","219"),("RFC","XXX010101XXX"),("Version","1.0")]), nsmap={'catalogocuentas':SATNS}, attrib={location_attribute: 'http://www.sat.gob.mx/catalogocuentas'})
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lxml.etree.pyx", line 2558, in lxml.etree.Element (src/lxml/lxml.etree.c:52829)
TypeError: Element() got multiple values for keyword argument 'attrib'
How can I fix it?
Thanks in advance!!
The problem is you are sending the Element() init method the same keyword argument twice. For your initialization your second argument is being used as the attrib keyword. Which in this instance is your OrderedDict() which contains all your attributes. You then try to supply it again which is where it runs into a collision. You can remedy this one of two ways:
You can add this attribute to your attribute OrderedDict() like so:
root = ET.Element('{%s}Catalogo' % SATNS, OrderedDict([("Ano","2014"),("Mes","02"),("TotalCtas","219"),("RFC","XXX010101XXX"),("Version","1.0"),("location_attribute","http://www.sat.gob.mx/catalogocuentas")]), nsmap={'catalogocuentas':SATNS})
Alternatively you could add it on the next line as well by doing this:
root.attrib["location_attribute"] = "http://www.sat.gob.mx/catalogocuentas"