I am using jira-python with Python 2.7 and Jira Server to set up components and filters. I want to add new filters when needed and update existing ones when applicable. From the non-progress of this request; JRASERVER-36045, I am not optimistic about the prospects of retrieving a list of existing (public) filters. I was however hoping that I would be able to use a Try/Except block to create a filter, like so:
try:
jira.create_filter(name=name_of_filter, jql=filter_str)
except JIRAError:
jira.update_filter(name=name_of_filter, jql=filter_str)
However, first of all, I get
NameError: name 'JIRAError' is not defined
What error type should I use?
Second; I think I need to provide a filter-ID instead of name to update it. But can I somehow get hold of the filter ID if I know the filter name?
To you first question: you will need to import JIRAError to use it. Something more like:
from jira import JIRA
from jira import JIRAError
jira = JIRA('https://jira.atlassian.com')
try:
jira.create_filter(name=name_of_filter, jql=filter_str)
except JIRAError:
jira.update_filter(name=name_of_filter, jql=filter_str)
Related
I am trying to use rasgo.get.dataset(fqtn='vw_orders_main') but I am getting an error.
APIError: Dataset with fqtn 'vw_orders_main' does not exist or this API key does not have access.
When using rasgo.get.dataset(), you can either:
pass in a dataset_id
rasgo.get.dataset(123)
pass in a fully qualified table name (fqtn)
rasgo.get.dataset(fqtn="DB.SCHEMA.TABLE")
pass in a resource_key
rasgo.get.dataset(resource_key='mykey')
From the appearance of the string you are using, I believe that is a resource key.
If you are using a variable called vw_orders_main to hold the FQTN string, then try it without the single quotes.
Examples:
vw_orders_main = "DB.SCHEMA.TABLE"
rasgo.get.dataset(fqtn=vw_orders_main)
or
rasgo.get.dataset(fqtn="DB.SCHEMA.TABLE")
or, if what you meant was resource_key,
rasgo.get.dataset(resource_key='vw_orders_main')
A resource_key is randomly assigned when a dataset is published, unless you specify the string yourself (like it appears that you did). It provides you the ability to tie multiple datasets as 1, thus allowing “versions”.
Resource Links: get dataset, publish dataset
I tried to take text from one field and set it modificated to another throught Execute Python Code.
recs = record.smt
for rec in recs:
details = pythonwhois.get_whois(rec)
if 'No match for' in str(details):
record.smt2='ok'
else:
record.smt2='denied'
Error: forbidden opcode
Please, help!
For the line:
details = pythonwhois.get_whois(rec)
You are using a external library pythonwhois which is not imported, how do you suppose to use that in your execution. As import statement is also not allowed, you can't just import any library.
instead of using dot operator, try to use write function.
if 'No match for' in str(details):
smt2='ok'
else:
smt2='denied'
record.write({'smt2': smt})
Also keep in mind that record is the record on which the action is triggered; may be void
I am using python 3. I use database to lookup the country of IP, if the IP is not in the database, return None or AAA. After all process, show the return result (either a country name or None or AAA ) in a new column on the data frame, Specifically, I have three columns that are date time and IP in the data frame, I would like to add a new column "code1" that shows the country name or None of this IP.
I add error exception in the code, however, it doesn't work. The code and error message are as below. Can anyone help?
The following is the report when I add "from geoip2.errors import AddressNotFoundError" to my code. I guess it means when there is address not found in the database, it return nothing rather a "none" (see, there is a empty square brackets), therefore, when I use df['code1']=code1, it reports the number of value is not equal to the number of index. (I am not sure).
In fact,my aim is to add a column to my original data frame that report the country of each ip or none if it is not in the database. Is there any other way to do so instead of " df['code1']=code1 "? Any help will be appreciated. Thanks
Exceptions are just like any other object in Python. They have to be defined somewhere. In this case, AddressNotFoundError is not defined so the interpreter has no idea what it means.
It has to be imported:
from geoip2.errors import AddressNotFoundError
or
import geoip2.errors.AddressNotFoundError
See relevant part of geoip2 documentation.
You can just leave out the AddressNotFoundError and instead do
try:
response1 = reader.country(row1)
code1.append(response1.country.iso_code)
except:
response1 = None
but if you really want to just except the AddressNotFoundError then at the top do
import geoip.errors.AddressNotFoundError
I'm new to LDAP. So I don't really know all my terms and fully understand all the terms yet. However, I'm working on an existing system and all the set up is done. I'm just adding a method to it.
I'm trying to write a method in Python using LDAP query. I've played around on LDAP Browser and can see that my query is correct. However, I'm not sure how to put it in a python method to return a list. The method needs to return a list of all the users' username. So far I have:
def getUsersInGroup(self, group):
searchQuery= //for privacy Im not going to share this
searchAttribute=["username"]
results = self.ldap.search_s(self.ldap_root, ldap.SCOP_SUBTREE,
searchQuery, searchAttribute)
I'm unsure how to go from here. I don't fully understand what the search_s method returns. I read online that its better to use search_s over search method because the while loop can be avoided. Could you please provide and example of where I can go from here. Thanks.
You need to perform a LDAP search something like:
# Find all Groups user is a member of:
import ldap
l = ldap.initialize("ldap://my_host")
l.simple_bind_s("[my_dn]", "[my_pass]")
myfilter = "(member=(CN=UserName,CN=Users,DC=EXAMPLE,DC=COM))"
# for all groups including Nested Groups (Only Microsoft Active Directory)
# (member:1.2.840.113556.1.4.1941:=CN=UserName,CN=Users,DC=EXAMPLE,DC=COM)
ldap_result = l.search("[BASE_DN]", ldap.SCOPE_SUBTREE, myfilter, None)
res_type, data = l.result(ldap_result, 0)
print(data)
You need to use the full dn of the user.
I am trying to use Google's admin directory API (with Google's python library).
I am able to list the users on the directory just fine, using some code like this:
results = client.users().list(customer='my_customer').execute()
However, those results do not include which groups the users are a member of. Instead, it appears that once I have the list of users, I then have to make a call to get a list of groups:
results = client.groups().list(customer='my_customer').execute()
And then go through each group and call the "members" api to see which users are in a group:
results = client.members().list(groupKey='[group key]').execute()
Which means that I have to make a new request for every group.
It seems to be horribly inefficient. There has to be a better way than this, and I'm just missing it. What is it?
There is no better way than the one you described (yet?): Iterate over groups and get member list of each one.
I agree that is not the answer you want to read, but it is also the way we do maintenance over group members.
The following method should be more efficient, although not 100% great :
For each user, call the groups.list method and pass the userKey parameter to specify that you only want groups who have user X as a member.
I'm not a Python developper, but it should look like this :
results = client.groups().list(customer='my_customer',userKey='user#domain.com').execute()
For each user:
results = client.groups().list(userKey=user,pageToken=None).execute()
where 'user' is the user's primary/alias email address or ID
This will return a page of groups the user is a member of, see:
https://developers.google.com/admin-sdk/directory/v1/reference/groups/list