I have a manager with one dict proxy. I want to access it from a different process. For brevity sample code only uses one process but assume we don't have a direct reference to it (as if the other process was created from the first one).
I register dict proxy dict1 under typeName 'd1' so I can access it remotely. I check the manager's registry and see the dict proxy there.
But when I try to access it by calling d1 I get a KeyError from the remote. I know I could create a method to access my dict, but there must be a direct way to access the dict proxy according to the documentation (python 2, chapter 16.6).
from multiprocessing.managers import SyncManager
from sys import stderr
proxy = SyncManager()
proxy.start()
dict1 = proxy.dict({'k1': 'blah'})
proxy.register('d1', dict1)
# next line shows that d1 is bound method of manager
print >>stderr, 'd1 is', proxy.d1
# next line produces a KeyError
print 'The value of d1 is', proxy.d1()
Run output
d1 is <bound method SyncManager.d1 of <multiprocessing.managers.SyncManager object at 0x10925dd10>>
Traceback (most recent call last):
File "/Users/adriancepleanu/PycharmProjects/AFX/UIproxy.py", line 32, in <module>
print 'The value of d1 is', proxy.d1()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/managers.py", line 667, in temp
token, exp = self._create(typeid, *args, **kwds)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/managers.py", line 567, in _create
id, exposed = dispatch(conn, None, 'create', (typeid,)+args, kwds)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/managers.py", line 105, in dispatch
raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError:
---------------------------------------------------------------------------
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/managers.py", line 207, in handle_request
result = func(c, *args, **kwds)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/managers.py", line 380, in create
self.registry[typeid]
KeyError: 'd1'
---------------------------------------------------------------------------
Found that the proxy server must be started after the call to register the new type; it appears that registrations made after the proxy was started will not function.
Related
I have two issues:
I'm calling G-Ads API to bulk remove ads (code)
for error_detail in error_details:
# Retrieve an instance of the google_ads_failure class from the client
failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
# Parse the string into a google_ads_failure message instance.
# To access class-only methods on the message we retrieve its type.
google_ads_failure = type(failure_message)
failure_object = google_ads_failure.deserialize(error_detail.value)
for error in failure_object.errors:
# Construct and print a string that details which element in
# the above ad_group_operations list failed (by index number)
# as well as the error message and error code.
print("A partial failure at index "
f"{error.location.field_path_elements[0].index} occurred "
f"\nError message: {error.message}\nError code: "
f"{error.error_code}")
index_array.append(error.location.field_path_elements[0].index)
error_array.append({"error_message": error.message, "error_code": error.error_code})
I get a partial error
And the code fails to parse it (taken form the official website)
My terminal shows:
Partial failures occurred. Details will be shown below.
Traceback (most recent call last):
File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\client.py", line 426, in get_type
message_class = getattr(type_classes, name)
File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\v8\__init__.py", line 1753, in __getattr__
raise AttributeError(f"unknown type {name!r}.")
AttributeError: unknown type 'google_ads_failure'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\projects\bowling\src\main.py", line 535, in <module>
main(args.top_id)
File "D:\projects\bowling\src\main.py", line 141, in main
removed_ads_count = remove_disapproved_ads_for_account(account)
File "D:\projects\bowling\src\main.py", line 206, in remove_disapproved_ads_for_account
remove_ads(ad_removal_operations, ads_to_remove_json, account_id)
File "D:\projects\bowling\src\main.py", line 300, in remove_ads
index_array, error_array = _print_results(response_chunk)
File "D:\projects\bowling\src\main.py", line 439, in _print_results
failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\client.py", line 428, in get_type
raise ValueError(
ValueError: Specified type 'google_ads_failure' does not exist in Google Ads API v8
failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
I think this should be -
failure_message = gAdsServiceWrapper.client.get_type("GoogleAdsFailure")
I am trying to build a Networkscanner that scans my localnetwork.
Here is how I would do it:
Create an ARP Request.
Create an Ethernet Frame.
Place the ARP Request inside the Ethernet Frame.
Send the combined frame and receive responses.
Then parse the responses and print the results.
Here is my code so far:
#!/usr/bin/env python3
import scapy.all as scapy
IP = 'here i would enter my IP adress'
def scan(ip):
arp_packet = scapy.ARP(pdst=ip)
broadcast_packet = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')
arp_broadcast_packet = broadcast_packet/arp_packet
scapy.srp(arp_broadcast_packet, timeout = 1, verbose = False)
scan(IP)
However I am getting the error message :
AttributeError: 'L2bpfSocket' object has no attribute 'ins'
Here is the complete message:
Traceback (most recent call last):
File "/Users/Uni/Dropbox/Mein Mac (Elias MacBook Pro)/Desktop/wifi2.py", line 12, in <module>
scan(IP)
File "/Users/Uni/Dropbox/Mein Mac (Elias MacBook Pro)/Desktop/wifi2.py", line 10, in scan
scapy.srp(arp_broadcast_packet, timeout = 1, verbose = False)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/sendrecv.py", line 552, in srp
s = conf.L2socket(promisc=promisc, iface=iface,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 242, in __init__
super(L2bpfListenSocket, self).__init__(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 62, in __init__
(self.ins, self.dev_bpf) = get_dev_bpf()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/core.py", line 114, in get_dev_bpf
raise Scapy_Exception("No /dev/bpf handle is available !")
scapy.error.Scapy_Exception: No /dev/bpf handle is available !
Exception ignored in: <function _L2bpfSocket.__del__ at 0x7fc3220493a0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 139, in __del__
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 211, in close
if not self.closed and self.ins is not None:
AttributeError: 'L2bpfSocket' object has no attribute 'ins'
Elias-MBP:~ Uni$
I read that it could be do to the program trying to close a L2bpfSocket that couldn't be created, therefore not having a Attribute ins.
However I have no clue how to fix this, or why the L2bpfSocket couldn't be created in the first place.
Make sure you're running your script as root.
The second issue isn't important, the main one being that Scapy can't open a /dev/bpf handler.
I'm trying to get this, https://github.com/joaquinlpereyra/twitterImgBot, to work
and it works and it seems ok.
But after some hours, it stops working and this error comes up:
*python3 twitterbot.py
Traceback (most recent call last):
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 118, in build_path
value = quote(self.session.params[name])
KeyError: 'id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "twitterbot.py", line 209, in <module>
main()
File "twitterbot.py", line 200, in main
orders()
File "twitterbot.py", line 118, in orders
timeline.delete_tweet_by_id(tweet.in_reply_to_status_id, api)
File "/home/user/Skrivebord/twitterboot/lo/bot/timeline.py", line 12, in delete_tweet_by_id
api.destroy_status(id_to_delete)
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 245, in _call
method = APIMethod(args, kwargs)
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 71, in __init__
self.build_path()
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 120, in build_path
raise TweepError('No parameter value found for path variable: %s' % name)
tweepy.error.TweepError: No parameter value found for path variable: id*
It seems like the Python has some problem because if I make a new install on a another PC it works for some hours and then stops.
Strange.
This is likely because tweet is not in reply to a status, so has an in_reply_to_status_id attribute that's None, so API.destroy_status is called with an id of None.
setattr() for an item in Redmine issues, is failing, with the following error.
Traceback (most recent call last):
File "E:\test\get_redmine_data.py", line 47, in <module>
print (item.assigned_to)
File "C:\Python27\lib\site-packages\redminelib\resources\standard.py", line 150, in __getattr__
return super(Issue, self).__getattr__(attr)
File "C:\Python27\lib\site-packages\redminelib\resources\base.py", line 164, in __getattr__
attr, encoded = self.encode(attr, decoded, self.manager)
File "C:\Python27\lib\site-packages\redminelib\resources\base.py", line 266, in encode
return attr, manager.new_manager(cls._resource_map[attr]).to_resource(value)
File "C:\Python27\lib\site-packages\redminelib\managers\base.py", line 29, in to_resource
return self.resource_class(self, resource)
File "C:\Python27\lib\site-packages\redminelib\resources\base.py", line 130, in __init__
self._decoded_attrs = dict(dict.fromkeys(relations_includes), **attributes)
TypeError: type object argument after ** must be a mapping, not str
I am trying to set some default assignee, for issues where the assignee is not set. The code fails at the line, where I print the attribute I just set. My code is given below:
redmine = Redmine('http://redmine_url', username='uname', password='pwd')
project = redmine.project.get('proj_name')
work_items = project.issues
for item in work_items:
assignee_not_set = getattr(item,'assigned_to',True)
if assignee_not_set == True:
print item.id
setattr(item,'assigned_to','Deepak')
print (item.assigned_to)
I also tried using the update() method,
redmine.project.update(item.id, assigned_to='Deepak')
That also fails with another error - redminelib.exceptions.ResourceNotFoundError: Requested resource doesn't exist.
I verifed that the issue id exists in Redmine.
You have several problems here:
The attribute name is assigned_to_id and not assigned_to
It accepts user id which is int and not a username which is str
No need to use setattr() here, just use item.assigned_to_id = 123
You need to call item.save() after setting assigned_to_id otherwise it won't be saved to Redmine
When you're trying to use update() method, you're using in on a Project resource and not on Issue resource, this is why you're getting ResourceNotFoundError
All this information is available in the docs: https://python-redmine.com/resources/issue.html
I'm trying to evaluate a number of processes in a multiprocessing pool but keep running into errors and I can't work out why... There's a simplified version of the code below:
class Object_1():
def add_godd_spd_column()
def calculate_correlations(arg1, arg2, arg3):
return {'a': 1}
processes = {}
pool = Pool(processes=6)
for i in range(1, 10):
processes[i] = pool.apply_async(calculate_correlations,
args=(arg1, arg2, arg3,))
correlations = {}
for i in range(0, 10):
correlations[i] = processes[i].get()
This returns the following error:
Traceback (most recent call last):
File "./02_results.py", line 116, in <module>
correlations[0] = processes[0].get()
File "/opt/anaconda3/lib/python3.5/multiprocessing/pool.py", line 608, in get
raise self._value
File "/opt/anaconda3/lib/python3.5/multiprocessing/pool.py", line 385, in
_handle_tasks
put(task)
File "/opt/anaconda3/lib/python3.5/multiprocessing/connection.py", line 206, in send
self._send_bytes(ForkingPickler.dumps(obj))
File "/opt/anaconda3/lib/python3.5/multiprocessing/reduction.py", line 50, in dumps
cls(buf, protocol).dump(obj)
AttributeError: Can't pickle local object 'SCADA.add_good_spd_column.<locals>.calculate_correlations
When I call the following:
correlations[0].successful()
I get the following error:
Traceback (most recent call last):
File "./02_results.py", line 116, in <module>
print(processes[0].successful())
File "/opt/anaconda3/lib/python3.5/multiprocessing/pool.py", line 595, in
successful
assert self.ready()
AssertionError
Is this because the process isn't actually finished before the .get() is called? The function being evaluated just returns a dictionary which should definitely be pickle-able...
Cheers,
The error is occurring because pickling a function nested in another function is not supported, and multiprocessing.Pool needs to pickle the function you pass as an argument to apply_async in order to execute it in a worker process. You have to move the function to the top level of the module, or make it an instance method of the class. Keep in mind that if you make it an instance method, the instance of the class itself must also be picklable.
And yes, the assertion error when calling successful() occurs because you're calling it before a result is ready. From the docs:
successful()
Return whether the call completed without raising an exception. Will raise AssertionError if the result is not ready.