I'm trying to update a user attribute in Active Directory using pyad. This is my code
from pyad import *
pyad.set_defaults(ldap_server="server.domain.local",
username="admin", password="password")
pyad.adobject.ADObject.update_attribute(self='testuser1', attribute='mail',
newvalue='my#email.com')
and this is the error i recieve.
Traceback (most recent call last):
File "c:\Users\Administrator\Desktop\scripts\AD-Edit-user.py", line 12, in
<module>
pyad.adobject.ADObject.update_attribute(self='testuser1', attribute='mail',
newvalue='my#email.com')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\pyad-0.5.20-py3.6.egg\pyad\adobject.py", line 318, in
update_attribute
elif pyadutils.generate_list(newvalue) != self.get_attribute(attribute):
AttributeError: 'str' object has no attribute 'get_attribute'
This makes me assume that I need to change the attribute type from str to something else. I have verified that mail is the correct attribute name.
I know ldap connection is working because i can create a user using a similar script.
Your problem is how you use pyad.
Specifically in this line:
pyad.adobject.ADObject.update_attribute(self='testuser1', attribute='mail',
newvalue='my#email.com')
if we look at the source of pyad.adobject.ADObject, we can see the following:
def update_attribute(self, attribute, newvalue, no_flush=False):
"""Updates any mutable LDAP attribute for the object. If you are adding or removing
values from a multi-valued attribute, see append_to_attribute and remove_from_attribute."""
if newvalue in ((),[],None,''):
return self.clear_attribute(attribute)
elif pyadutils.generate_list(newvalue) != self.get_attribute(attribute):
self._set_attribute(attribute, 2, pyadutils.generate_list(newvalue))
if not no_flush:
self._flush()
self here is not a parameter of the function, it is a reference to the class instance. Your call includes self='testuser1' which is str.
Please lookup the documentation on how to use this function / functionality / module, here. You will notice that there is no "self"... other than looking into the source code I am not sure how you got to the conclusion you needed self.
I have no way of testing the following, but this is roughly how it should work:
# first you create an instance of the object, based on
# the distinguished name of the user object which you
# want to change
my_ad_object = pyad.adobject.ADObject.from_dn('the_distinguished_name')
# then you call the update_attribute() method on the instance
my_ad_object.update_attribute(attribute='mail', newvalue='my#email.com')
Related
I have the following code running on AWS lambda, but getting the following error.
Error
[ERROR] AttributeError: 'str' object has no attribute 'source_instructions'
Traceback (most recent call last):
File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 56, in submit
result_set = self._client.submit(bytecode, request_options=self._extract_request_options(bytecode))
File "/var/task/gremlin_python/driver/driver_remote_connection.py", line 81, in _extract_request_options
options_strategy = next((x for x in bytecode.source_instructionsEND RequestId: 4ee8073c-e941-43b3-8014-8717893b3188
Source code
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
def test_neptune(host):
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))
query = "g.V().groupCount().by(label).unfold().project('label','count').by(keys).by(values)"
response = remoteConn.submit(query)
print("response-> {}" .format(response))
# iterate repsonse
# go thru label
for set_item in response:
for item in set_item:
print("item-> item: {}".format(item))
remoteConn.close()
test_neptune()
Your DriverRemoteConnection call is wrong. You have:
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin','g'.format(host))
So you are sending {} as the hostname, and passing 'g' as a second parameter, which is probably where the error comes from. I don't know what you intended the 'g' for, but you probably want:
remoteConn = DriverRemoteConnection('wss://{}:8182/gremlin'.format(host))
If you send the query as a text string you need to create the Client object differently or write the query as in-line Python. There are two examples at (1) and (2) that show each option. The error you are seeing is because the server is trying to find Gremlin bytecode in the packet sent but only found a string (which does not have a source_instructions method).
Using a DriverRemoteConnection you can use a Python line of code such as:
result = (g.V().groupCount().
by(label).
unfold().
project('label','count').
by(keys).
by(values).
next())
If you actually want/need to send the query as a string instead of bytecode, please see my answer to this question
https://github.com/krlawrence/graph/blob/master/sample-code/basic-client.py
https://github.com/krlawrence/graph/blob/master/sample-code/glv-client.py
I am facing issue with the Code which is framed with Class.
Basically before It was simply a file with functions defined in it.
So When I was trying to execute the file using command python filename.py, It is working fine as needed.
Code sample is as follows:
# Getting the tenant list
# Fetch the creation_date of tenant if exists
def get_tenants():
# Fetch tenant list
tenants_list = keystone.tenants.list()
# Fetch tenant ID
for tenant in tenants_list:
tenant_id = tenant.id
.
.
.
get_tenants()
So as shown in aboce code in the file I am trying to call get_tenants function, Also it is working fine as needed with no error.
Now I have Created the Class then moved all the functions in to the same.
Above function is Rewritten as follows now.
def get_tenants(self):
# Fetch tenant list
tenants_list = keystone.tenants.list()
# Fetch tenant ID
for tenant in tenants_list:
tenant_id = tenant.id
Then I have called the Function as follows:
billing = BillingEngine()
billing.get_tenants()
But, now I am getting the error as follows:
root#devstack:/opt/open-stack-tools/billing# python new_class.py
Traceback (most recent call last):
File "new_class.py", line 281, in <module>
BillingEngine().get_tenants()
File "new_class.py", line 75, in get_tenants
tenants_list = keystone.tenants.list()
NameError: global name 'keystone' is not defined
Note: Will provide the full file if needed.
May be you must define this?
class Example(object):
keystone = Keystone()
def get_tenants(self):
self.keystone.do_something()
I'm having some trouble with SalesForce, I've never used it before so I'm not entirely sure what is going wrong here. I am using the simple_salesforce python module. I have successfully pulled data from SalesForce standard objects, but this custom object is giving me trouble. My query is
result = sf.query("Select Name from Call_Records__c")
which produces this error:
Traceback (most recent call last):
File "simple.py", line 15, in <module>
result = sf.query("Select Name from Call_Records__c")
File "/usr/local/lib/python2.7/dist-packages/simple_salesforce/api.py", line 276, in query
_exception_handler(result)
File "/usr/local/lib/python2.7/dist-packages/simple_salesforce/api.py", line 634, in _exception_handler
raise exc_cls(result.url, result.status_code, name, response_content)
simple_salesforce.api.SalesforceMalformedRequest: Malformed request https://sandbox.company.com/services/data/v29.0/query/?q=Select+Name+from+Call_Records__c. Response content: [{u'errorCode': u'INVALID_TYPE', u'message': u"\nSelect Name from Call_Records__c\n ^\nERROR at Row:1:Column:18\nsObject type 'Call_Records__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.
Please reference your WSDL or the describe call for the appropriate names."}]
I've tried it with and without the __c for both the table name and the field name, still can't figure this out. Anything blatantly wrong?
Make sure your result is Call_Records__c/CallRecords__c
Call_Records__c result = sf.query("Select Name from Call_Records__c")
Or
CallRecords__c result = sf.query("Select Name from CallRecords__c")
Try using -
result = sf.query("Select Name from CallRecords__c")
I'm parsing objects returned by the suds client from a Web Services SOAP API
I have a list of attributeObjects, like
(defectStateAttributeValueDataObj){
attributeDefinitionId =
(attributeDefinitionIdDataObj){
name = "Comment"
}
attributeValueId =
(attributeValueIdDataObj){
name = "Owner changed because of default owner assignment specified in the component map"
}
}
and
(defectStateAttributeValueDataObj){
attributeDefinitionId =
(attributeDefinitionIdDataObj){
name = "OwnerName"
}
attributeValueId =
(attributeValueIdDataObj){
name = "Schmoe, Joe"
}
}
I use the following loop to extract key/value pairs:
for defect in myDefectsPage.mergedDefects :
print defect.cid,
for attribute in defect.defectStateAttributeValues:
print attribute
attr= attribute.attributeDefinitionId.name
val=attribute.attributeValueId.name
print attr,'=',val,
print ""
(The above objects are results of the print attribute command)
This will work as expected for EVERY attribute, except the one where attribute.attributeDefinitionId.name == "Comment"
for that one I get the
Traceback (most recent call last):
File , line 63, in
val=attribute.attributeValueId.name
AttributeError: 'Text' object has no attribute 'name'
which is strange, because if I use
val=attribute.attributeValueId #.name
it will print
Commment = (attributeValueIdDataObj){
name = "Owner changed because of default owner assignment specified in the component map"
}
So it looks like it IS an attributeValueIdDataObj and DOES have a name attribute.
I used the suds DEBUG logging and the XML return elements look exactly the same regardless of what the attribute.attributeDefinitionId.name is.
I have no idea how it changes into a 'Text' object when trying to access the name attribute
Any ideas?
On further examination (and printing out the type of the returned object when exception happened) this was a bug in the web services SOAP server.
When a Comment was empty, it returned an
<attributeValueId/>
tag,
instead of the proper
<attributeValueId>
<name/>
</attributeValueId>
object. so it resulted in sax.Text object instead of the suds.attributeValueIdDataObj object
So no python or suds mystery to solve.
Sorry for the false alarm...
Code:
for k in dir(parse_rest.User):
print parse_rest.User[k]
Error:
Traceback (most recent call last):
File "/home/ntresch/Development/webapp/appcode.py", line 53, in <module>
for k in dir(parse_rest.User):
AttributeError: 'module' object has no attribute 'User'
The docs show the following:
#Users
#You can sign up, log in, modify or delete users as well, using the User object. You sign a user up as follows:
u = parse_rest.User.signup("dhelmet", "12345", phone="555-555-5555")
#or log in an existing user with
u = parse_rest.User.login("dhelmet", "12345")
# Once a User has been logged in, it saves its session so that it can be edited or deleted:
u.highscore = 300
u.save()
u.delete()
I really want to know what all I can do with the user object. This behavior seems wonky.
This was a case of (at the time) out-of-date documentation, fixed as of 3/11/2013. The way to access the User class is not parse_rest.User but:
from parse_rest.user import User
The answer is don't use that library. My colleague has one we home rolled checked into our source tree and we're planning on releasing one. When we do I will post a link here for completeness. :)