I am trying to access the worklogs in python by using the jira python library. I am doing the following:
issues = jira.search_issues("key=MYTICKET-1")
print(issues[0].fields.worklogs)
issue = jira.search_issues("MYTICKET-1")
print(issue.fields.worklogs)
as described in the documentation, chapter 2.1.4. However, I get the following error (for both cases):
AttributeError: type object 'PropertyHolder' has no attribute 'worklogs'
Is there something I am doing wrong? Is the documentation outdated? How to access worklogs (or other fields, like comments etc)? And what is a PropertyHolder? How to access it (its not described in the documentation!)?
This is because it seems jira.JIRA.search_issues doesn't fetch all "builtin" fields, like worklog, by default (although documentation only uses vague term "fields - [...] Default is to include all fields"
- "all" out of what?).
You either have to use jira.JIRA.issue:
client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")
or explicitly list fields which you want to fetch in jira.JIRA.search_issues:
client = jira.JIRA(...)
issue = client.search_issues("key=MYTICKET-1", fields=[..., 'worklog'])[0]
Also be aware that this way you will get at most 20 worklog items attached to your JIRA issue instance. If you need all of them you should use jira.JIRA.worklogs:
client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")
worklog = issue.fields.worklog
all_worklogs = client.worklogs(issue) if worklog.total > 20 else worklog.worklogs
This question here is similar to yours and someone has posted a work around.
There is a also a similar question on Github in relation to attachments (not worklogs). The last answer in the comments has workaround that might assist.
Related
I'm trying to use Tweepy (version 4.4.0) to get a user's description but it's seemingly not working:
u = api.get_user(username='XXXX', user_fields=['description'])
but the output of this is simply:
Response(data=<User id=123 name=XXX username=XXX>, includes={}, errors=[], meta={})
So it's getting me the name and id fine, but it's returning an empty for any user fields.
Note I've also tried with user_auth: 1, but I get 'Unauthorized: 401' - but from what I've seen around, I don't think user authentication is the problem here... but maybe it is?
Any advice would be great!
api seems to be an instance of tweepy.Client here.
From the relevant FAQ section in Tweepy's documentation:
Why am I not getting expansions or fields data with API v2 using Client?
If you are simply printing the objects and looking at that output, the string representations of API v2 models/objects only include the default attributes that are guaranteed to exist.
The objects themselves still include the relevant data, which you can access as attributes or by key, like a dictionary.
The user object being returned in the response should have a description field with the user's description.
You can access the description with: u.data.description
Keep in mind that the description may be blank some times, try with created_at to be sure it works.
Sample code for extracting description of any twitter user is as follows
import tweepy
auth = tweepy.OAuth2BearerHandler(os.environ.get("TWITTER_API_KEY"))
api = tweepy.API(auth)
user = api.get_user(screen_name="TechWiser", include_entities=False)
description = user._json['description']
user._json contain many other key, value pair that you can explore
I am new to use bioservices Python package. Now I am going to use that to retrieve PMIDs for two citations, given the specified information and this is the code I have tried:
from bioservices import EUtils
s = EUtils()
print(s.ECitMatch("pubmed",retmode="xml", bdata="proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|%0Dscience|1987|235|182|palmenberg+ac|Art2|"))
But it occurs an error:
"TypeError: ECitMatch() got multiple values for argument 'bdata'".
Could anyone help me to solve that problem?
I think the issue is that you have an unnamed argument (pubmed); if you look at the source code, you can see that the first argument should be bdata; if you provide the arguments like you do, it is, however, unclear whether bdata is "pubmed" or the named argument bdata, therefore the error you obtain.
You can reproduce it with this minimal example:
def dummy(a, b):
return a, b
dummy(10, a=3)
will return
TypeError: dummy() got multiple values for argument 'a'
If you remove "pubmed", the error disappears, however, the output is still incomplete:
from bioservices import EUtils
s = EUtils()
print(s.ECitMatch("proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|%0Dscience|1987|235|182|palmenberg+ac|Art2|"))
returns
'proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|2014248\n'
so only the first publication is taken into account. You can get the results for both by using the correct carriage return character \r:
print(s.ECitMatch(bdata="proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|\rscience|1987|235|182|palmenberg+ac|Art2|"))
will return
proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|2014248
science|1987|235|182|palmenberg+ac|Art2|3026048
I think you neither have to specify retmod nor the database (pubmed); if you look at the source code I linked above you can see:
query = "ecitmatch.cgi?db=pubmed&retmode=xml"
so seems it always uses pubmed and xml.
Two issues here: syntaxic and a bug.
The correct syntax is:
from bioservices import EUtils
s = EUtils()
query = "proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|%0Dscience|1987|235|182|palmenberg+ac|Art2|"
print(s.ECitMatch(query))
Indeed, the underlying service related to ICitMatch has only one database (pubmed) and one format (xml) hence, those 2 parameters are not available : there are hard-coded. Therefore, only one argument is required: your query.
As for the second issue, as pointed above and reported on the bioservices issues page, your query would return only one publication. This was an issue with the special character %0D (in place of a return carriage) not being interpreted corectly by the URL request. This carriage character (either \n, \r or %0d) is now taken into account in the latest version on github or from pypi website if you use version 1.7.5
Thanks to willigot for filling the issue on bioservices page and bringing it to my attention.
disclaimer: i'm the main author of bioservices
I am trying to execute this following code to push data to Salesforce using the simple_salesforce python library :
from simple_salesforce import Salesforce
staging_df = hive.execute("select * from hdmni")
staging_df = staging_df.toPandas()
# # staging_df['birth_date']= staging_df['birth_date'].dt.date
staging_df['birth_date'] = staging_df['birth_date'].astype(str)
staging_df['encounter_start_date'] = staging_df['encounter_start_date'].astype(str)
staging_df['encounter_end_date'] = staging_df['encounter_end_date'].astype(str)
bulk_data = []
for row in staging_df.itertuples():
d= row._asdict()
del d['Index']
bulk_data.append(d)
sf = Salesforce(password='', username='', security_token='')
sf.bulk.Delivery_Detail__c.insert(bulk_data)
I am getting this error while trying to send dictionary to salesforce :
SalesforceMalformedRequest: Malformed request
https://subhotutorial-dev-ed.my.salesforce.com/services/async/38.0/job/7500o00000HtWP6AAN/batch/7510o00000Q15TnAAJ/result.
Response content: {'exceptionCode': 'InvalidBatch',
'exceptionMessage': 'Records not processed'}
There's something about your query that is not correct. While I don't know your use case, by reading this line, you can tell that you are attempting to insert into a custom object/entity in Salesforce:
sf.bulk.Delivery_Detail__c.insert(bulk_data)
The reason you can tell is because of the __c suffix, which gets appended onto custom objects and fields (that's two underscores, by the way).
Since you're inserting into a custom object, your fields would have to be custom, too. And note, you've not appended that suffix onto them.
Note: Every custom object/entity in Salesforce does come with a few standard fields to support system features like record key (Id), record name (Name), audit fields (CreatedById, CreatedDate, etc.). These wouldn't have a suffix. But none of the fields you reference are any of these standard system fields...so the __c suffix would be expected.
I suspect that what Salesforce is expecting in your insert operation are field names like this:
Birth_Date__c
Encounter_Start_Date__c
Encounter_End_Date__c
These are referred to as the API name for both objects and fields, and anytime code interacts with them (whether via integration, or on code that executes directly on the Salesforce platform) you need to make certain you're using this API name.
Incidentally, you can retrieve this API name through a number of ways. Probably easiest is to log into your Salesforce org, and in Setup > Object Manager > [some object] > Fields and Relationships you can view details of each field, including the API name. Here's a screen shot.
You can also use SObject describe APIs, either in native Apex code, or via integration and either the REST or SOAP APIs. Here's part of the response from the describe API request to the describe REST endpoint for the same object as my UI example above, found here at https://[domain]/services/data/v47.0/sobjects/Expense__c/describe:
Looking at the docs for the simple-salesforce python library you're using, they've surfaced the describe API. You can find some info under Other Options. You would invoke it as sf.SObject.describe where "SObject" is the actual object you want to find the information about. For instance, in your case you would use:
sf.Delivery_Detail__c.describe()
As a good first troubleshooting step when interacting with a Salesforce object, I'd always recommend double-checking correctly referencing an API name. I can't tell you how many times I've bumped into little things like adding or missing an underscore. Especially with the __c suffix.
I'm trying to change a username using the Admin SDK. I'm trying the following code to update this, using a dict object to store the new info, and using patch to update:
userinfo['primaryEmail'] = D['new_user'] + '#' + D['domain']
appsservice.users().patch(userKey = userEmail, body=userinfo)
It doesn't seem to be working, when I look at the admin console. The original username remains unchanged. I'm just wondering if I'm using the correct method. Should I be updating a different variable than primaryEmail or without using the domain affiliation? Seems like I'm just missing something rather obvious.
Thanks,
Tom
Add:
.execute()
To the end of the 2nd line to actually execute the api operation.
How can I get the minutes spent from a worklog from an issue using the jira-python library?
Using the jirashell I see that the issue has the attribute issue.fields.worklog, however when I try to access that in my python code I get the error: AttributeError: type object 'PropertyHolder' has no attribute 'worklog'.
If I create a jira client and do jira_client.worklogs(ticket.key) in my python code, it returns a list of Worklogs and their ids but I don't know what to do with that. I see in the documentation there's a worklog() function that takes in the issue id, and the worklog id, but I don't understand what it returns and how I would use that/if it is what I'm looking for.
I found a roundabout way of doing it through the client.
As I iterate through each issue I get the list of worklogs per ticket by doing worklogs = jira_client.worklogs(issue.key) and then i iterate through all of the worklog items in the worklogs list (a nested for loop):
for worklog in worklogs:
totaltime += readtime(worklog.timeSpent)
Using the jirashell I accessed a specific worklog of a specific ticket: wl = jira_client.worklog(<issue key>, <worklog id>) then I typed in wl. and pressed TAB, it listed the following:
wl.author, wl.comment, wl.created, wl.delete, wl.find, wl.id, wl.raw, wl.self, wl.started,
wl.timeSpent, wl.timeSpentSeconds, wl.update, wl.updateAuthor, wl.updated
(Note: you need to include the period at the end of wl before pressing tab)
Running wl.timespent in the jirashell gave me gave me a unicode string with the number and then h or m for hour or minute (for example: u'6h'). Then I new that once I generated the worklog object in my loop above, I could access the time by using the timepsent attribute.
(Note: My readtime function turns the string into an integer and converts hours to minutes, and is not shown here)
The jirashell really helps with trying to find the attributes of the fields, etc. (Note: you need to install jira-python in addition to jira in order to run jirashell. Also if you installed jira-python in your virtualenv you need to run env/bin/jirashell from your command line once you are in your project's directory.)