python-jira add_worklog() giving internal error

I am trying to use add_worklog() with a particular startitme. No matter what , In all the formats, the JIRA responds with a 500 internal error. 

j='JIRA-314'

dateString="2016-01-27T03:31:45.000"

jira.add_worklog(j,'4h',None,None,None,None,None,dateString,None)

 

I tried passing the datetime object also. still same error. Can someone comment about this. the documentation has no example of specific start date. I

dt1 = datetime(2016,1, 27, 16, 30, tzinfo=None)
dt1.strftime("%Y/%m/%dT%H:%M:%S.000%z")
jira.add_worklog(j,'4h',None,None,None,None,None,dt,None)

 

Error seen is pasted below. 

File "C:\Users\rramachandran\AppData\Local\Programs\Python\Python35-32\lib\site-packages\jira\resilientsession.py", line 45, in raise_on_error
r.status_code, error, r.url, request=request, response=r, **kwargs)
jira.exceptions.JIRAError: JiraError HTTP 500
text: Internal server error
url: <edited out> 
response headers = {'Server': 'Apache-Coyote/1.1', 'Transfer-Encoding': 'chunked', 'X-Seraph-LoginReason': 'OK', 'Content-Type': 'application/json;charset=UTF-8', 'Cache-Control': 'no-cache, no-store, no-transform', 'X-AUSERNAME': 'rramachandran', 'Date': 'Tue, 15 Mar 2016 08:26:06 GMT', 'X-AREQUESTID': '266x2278785x2', 'Connection': 'close', 'X-ASESSIONID': '1r9n0ie'}
response text = {"errorMessages":["Internal server error"],"errors":{}}

 

It works fine if the pass the value None. But then the work will be logged only on the current date. 

jira.add_worklog(j,'4h',None,None,None,None,None,None,None)

 

 

2 answers

Hi Rahul,

I'm facing similar issue. I solved it by adding a small fix in the client.py code of the python jira module.

client.py (line 1222)
--------------------------
if started is not None:             # based on REST Browser it needs: "2014-06-03T08:21:01.273+0000"
             data['started'] = started.strftime("%Y-%m-%dT%H:%M:%S.000%z") + "+0000"

Kind Regards,

Ronnie

Thanks Ronnie,

I did not want to hardcode the +0000 in my copy of client.py. Instead I solved this problem via installing the tzlocal package:

 

Install the tzlocal module using pip install tzlocal into your virtualenv.

Import it:

 

from tzlocal import get_localzone

from datetime import datetime

 

then in code before you call jira.add_worklog, localize your date:

tz = get_localzone()
started_date = tz.localize(started_date)

 

Then pass started_date to the started argument of jira.add_worklog().

 

References:

  1. http://stackoverflow.com/questions/1111056/get-time-zone-information-of-the-system-in-python#comment26350543_1111079
  2. https://pypi.python.org/pypi/tzlocal

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

172 views 1 17
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you