How to delete ADUser using Python pyad module - python

I'm having a problem with deleting ADUser.
pyad.set_defaults(ldap_server="dc1.domain.com", username="service_account", password="mypassword")
user = aduser.ADUser.from_dn("cn=myuser, ou=staff, dc=domain, dc=com")
user.delete()
Unfortunately I could not figure out how to format this text to look like a real traceback
Traceback (most recent call last):
File "C:/Automation/qa/robot2/python_lib/keywords/AD/unittest.py", line 34,
in <module>
ad_connect.bg_ad_user_remove(user_login='vasya.oconnor#test-acme.com',dn_string= dn_string)
File "C:\Automation\qa\robot2\python_lib\keywords\AD\_bg_ad_general.py", line 156, in bg_ad_user_remove
user.delete()
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 537, in delete
if not parent:
File "C:\Python27\lib\site-packages\future\types\newobject.py", line 90, in __nonzero__
return type(self).__len__(self)
AttributeError: type object 'ADContainer' has no attribute '__len__'

Related

Getting weird error on running python in cmd then continue normally

When I run python on cmd I get this weird error:
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site.py", line 446, in register_readline
import readline
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\readline.py", line 34, in <module>
rl = Readline()
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
BaseReadline.__init__(self)
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
mode.init_editing_mode(None)
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
self._bind_key('space', self.self_insert)
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
if not callable(func):
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
return isinstance(x, collections.Callable)
AttributeError: module 'collections' has no attribute 'Callable'
But then I continue using python normally:
>>>
I did not find any effects of this problem python is running normally but I do not want it to appear and to know what does it do.

AttributeErrors when adding variables/constraints to Gurobi persistent

I am trying to modify a model by adding variables/constraints and re-solving the updated model, following the guide.
The problem is that both cases fail with attribute errors, for a variable:
Traceback (most recent call last):
File "seqdesign.py", line 98, in <module>
main()
File "seqdesign.py", line 71, in main
problem._solver.add_var(problem._model.McBernoulliTrials)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 153, in add_var
self._add_var(var)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 208, in _add_var
vtype = self._gurobi_vtype_from_var(var)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 377, in _gurobi_vtype_from_var
if var.is_binary():
AttributeError: 'IndexedVar' object has no attribute 'is_binary'
And for a constraint:
Traceback (most recent call last):
File "seqdesign.py", line 98, in <module>
main()
File "seqdesign.py", line 71, in main
problem._solver.add_constraint(problem._model.McBernoulliTrialsSetPositive)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 132, in add_constraint
self._add_constraint(con)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 272, in _add_constraint
if is_fixed(con.body):
AttributeError: 'IndexedConstraint' object has no attribute 'body'
Is the problem that I am using indexed variables and constraints? How to make this work without migrating all code from pyomo.environ to pyomo.core?
You cannot pass an IndexedVar or and IndexedConstraint into the add_var and add_constraint methods. You have to loop over the individual variables and constraints and add them one at a time:
for v in my_var.values():
solver.add_var(v)
for c in my_con.values():
solver.add_constraint(c)
Additionally, you can check if a variable or constraint is indexed with my_var.is_indexed() or my_con.is_indexed().

what is the replacement of wikipedia.getSite()? or is it still usable?

I ran a pywikibot sample code,
but it is aborted due to AttributeError.
Traceback is ...
Traceback (most recent call last):
File "pwb.py", line 270, in <module>
if not main():
File "pwb.py", line 264, in main
run_python_file(filename, [filename] + args, argvu, file_package)
File "pwb.py", line 109, in run_python_file
main_mod.__dict__)
File ".\cochonBot.py", line 81, in <module>
main()
File ".\cochonBot.py", line 52, in main
stub_list = cat_list_rec(u'遺꾨쪟:?좊쭑湲 遺꾨쪟', stub_ignore_cats)
File ".\cochonBot.py", line 14, in cat_list_rec
cat = catlib.Category(wikipedia.getSite(), top_cat)
AttributeError: 'module' object has no attribute 'getSite'
<type 'exceptions.AttributeError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort
what is the replacement of wikipedia.getSite()? or is it still usable?
You can simply use pywikibot.Site() instead.

How to add chain id in pdb

By using biopython library, I would like to add chains ids in my pdb file.
I'm using
p = PDBParser()
structure=p.get_structure('mypdb',mypdb.pdb)
model=structure[0]
model.child_list=["A","B"]
But I got this error:
Traceback (most recent call last):
File "../../principal_axis_v3.py", line 319, in <module>
main()
File "../../principal_axis_v3.py", line 310, in main
protA=read_PDB(struct,ch1,s1,e1)
File "../../principal_axis_v3.py", line 104, in read_PDB
chain=model[ch]
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/PDB/Entity.py", line 38, in __getitem__
return self.child_dict[id]
KeyError: 'A'
I tried to changes the keys in th child.dict, butI got another error:
Traceback (most recent call last):
File "../../principal_axis_v3.py", line 319, in <module>
main()
File "../../principal_axis_v3.py", line 310, in main
protA=read_PDB(struct,ch1,s1,e1)
File "../../principal_axis_v3.py", line 102, in read_PDB
model.child_dict.keys=["A","B"]
AttributeError: 'dict' object attribute 'keys' is read-only
How can I add chains ids ?
Your error is that child_list is not a list with chain IDs, but of Chain objects (Bio.PDB.Chain.Chain). You have to create Chain objects and then add them to the structure. A lame example:
from Bio.PDB.Chain import Chain
my_chain = Chain("C")
model.add(my_chain)
Now you can access the model child_dict:
>>> model.child_dict
{'A': <Chain id=A>, 'C': <Chain id=C>}
>>> model.child_dict["C"]
<Chain id=C>

Django does not allow to get/create new object: QuerySet object has no attribute get_or_create

I am using Python 3.2 with Django 1.6.2 on PostgreSQL
When trying to conditionally create object using get_or_create shortcut, I get AttributeError.
Of course, the workaround would be to catch the exception when trying to get the object and then create it. But can it be done using regular get_or_create?
'QuerySet' object has no attribute 'get_or_create'
Traceback (most recent call last):
File "/Users/urk/Documents/virtualenv/pycharm_python_3_3/lib/python3.3/site-packages/tastypie/resources.py", line 195, in wrapper
response = callback(request, *args, **kwargs)
File "/Users/urk/Documents/virtualenv/pycharm_python_3_3/lib/python3.3/site-packages/tastypie/resources.py", line 426, in dispatch_list
return self.dispatch('list', request, **kwargs)
File "/Users/urk/Documents/virtualenv/pycharm_python_3_3/lib/python3.3/site-packages/tastypie/resources.py", line 458, in dispatch
response = method(request, **kwargs)
File "/Users/urk/Documents/virtualenv/pycharm_python_3_3/lib/python3.3/site-packages/tastypie/resources.py", line 1320, in post_list
updated_bundle = self.obj_create(bundle, **self.remove_api_resource_names(kwargs))
File "/Users/urk/Documents/xxx/app/api/userresource.py", line 51, in obj_create
api_key, created = ApiKey.objects.get_or_create(user=rv.obj)
File "/Users/urk/Documents/virtualenv/pycharm_python_3_3/lib/python3.3/site-packages/django/db/models/manager.py", line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
AttributeError: 'QuerySet' object has no attribute 'get_or_create'
EDIT: Code sample.
The following code from python manage.py shell gives the exception
from django.contrib.auth.models import User
User.objects.get_or_create(username='tu')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/urk/Documents/virtualenv/pycharm_python_3_3/lib/python3.3/site-packages/django/db/models/manager.py", line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
AttributeError: 'QuerySet' object has no attribute 'get_or_create'
Recreating virtual environment as suggested by #AndreyNelubin solved the problem.

Categories

Resources