I have set up ad manager credentials. I'm trying to access the Admanager API, im getting the following error.
from googleads import ad_manager
client = ad_manager.AdManagerClient.LoadFromStorage()
network_service = client.GetService('NetworkService', version='v201902')
current_network = network_service.getCurrentNetwork()
the error im facing is:
Fault Traceback (most recent call last)
~\Anaconda3\lib\site-packages\googleads\common.py in MakeSoapRequest(*args)
1381 return soap_service_method(
-> 1382 *packed_args, _soapheaders=soap_headers)['body']['rval']
1383 except zeep.exceptions.Fault as e:
~\Anaconda3\lib\site-packages\zeep\proxy.py in __call__(self, *args, **kwargs)
41 self._proxy._client, self._proxy._binding_options,
---> 42 self._op_name, args, kwargs)
43
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in send(self, client, options, operation, args, kwargs)
131
--> 132 return self.process_reply(client, operation_obj, response)
133
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in process_reply(self, client, operation, response)
193 if response.status_code != 200 or fault_node is not None:
--> 194 return self.process_error(doc, operation)
195
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in process_error(self, doc, operation)
287 actor=None,
--> 288 detail=etree_to_string(doc))
289
Fault: Unknown fault occured
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-16-991c0839fc99> in <module>()
----> 1 current_network = network_service.getCurrentNetwork()
~\Anaconda3\lib\site-packages\googleads\common.py in MakeSoapRequest(*args)
1385 if e.detail is not None:
1386 underlying_exception = e.detail.find(
-> 1387 '{%s}ApiExceptionFault' % self._GetBindingNamespace())
1388 fault_type = self.zeep_client.get_element(
1389 '{%s}ApiExceptionFault' % self._GetBindingNamespace())
TypeError: a bytes-like object is required, not 'str'
You are probably missing permissions with your configured service account. Make sure the account has access to ad-manager and scopes are configured properly.
I suggest to do it this way:
class Adx:
def __init__(self):
self.GOOGLEADS_YAML = 'googleads.yaml'
self.GOOGLEADS_VERSION = 'v202111'
self.google_keys = self.GOOGLEADS_YAML
def activate(self):
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage(self.google_keys)
Related
Hi i am having issues with loading the .s2p file
when i ran the following code
import skrf as rf
from skrf import Network, Frequency
data1 = rf.Network('/Users/pradeeps/Desktop/Project/meas2018_07_06/300MHzNLOSX1DPS.s2p')
It showed the following error as shown below
---------------------------------------------------------------------------
UnpicklingError Traceback (most recent call last)
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:450, in Network.__init__(self, file, name, params, comments, f_unit, s_def, **kwargs)
449 try:
--> 450 self.read(fid)
451 except UnicodeDecodeError: # Support for pickles created in Python2 and loaded in Python3
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:2357, in Network.read(self, *args, **kwargs)
2356 from .io.general import read
-> 2357 self.copy_from(read(*args, **kwargs))
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/io/general.py:140, in read(file, *args, **kwargs)
139 try:
--> 140 obj = pickle.load(fid, *args, **kwargs)
141 except (UnpicklingError, UnicodeDecodeError) as e:
142 # if fid is seekable then reset to beginning of file
UnpicklingError: invalid load key, '3'.
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
Untitled-1.ipynb Cell 2' in <cell line: 1>()
----> 1 data1 = rf.Network('/Users/pradeeps/Desktop/Project/meas2018_07_06/300MHzNLOSX1DPS.s2p')
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:458, in Network.__init__(self, file, name, params, comments, f_unit, s_def, **kwargs)
456 filename = fid.name
457 fid.close()
--> 458 self.read_touchstone(filename, self.encoding)
460 if name is None and isinstance(file, str):
461 name = os.path.splitext(os.path.basename(file))[0]
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:1956, in Network.read_touchstone(self, filename, encoding)
1953 touchstoneFile = touchstone.Touchstone(filename, encoding=encoding)
1955 if touchstoneFile.get_format().split()[1] != 's':
-> 1956 raise NotImplementedError('only s-parameters supported for now.')
1958 self.comments = touchstoneFile.get_comments()
1960 try:
NotImplementedError: only s-parameters supported for now.
As shown in this particular code i used scikit-rf is there any other package that i should use in this particular instance or am i doing anything wrong.
Thank you
This is the error
ValueError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in _get_request_token(self, access_type)
65 url += '?x_auth_access_type=%s' % access_type
---> 66 return self.oauth.fetch_request_token(url)
67 except Exception as e:
17 frames
/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth1_session.py in fetch_request_token(self, url, realm, **request_kwargs)
286 self._client.client.realm = " ".join(realm) if realm else None
--> 287 token = self._fetch_token(url, **request_kwargs)
288 log.debug("Resetting callback_uri and realm (not needed in next phase).")
/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth1_session.py in _fetch_token(self, url, **request_kwargs)
364 log.debug("Fetching token from %s using client %s", url, self._client.client)
--> 365 r = self.post(url, **request_kwargs)
366
/usr/local/lib/python3.6/dist-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
577
--> 578 return self.request('POST', url, data=data, json=json, **kwargs)
579
/usr/local/lib/python3.6/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
515 )
--> 516 prep = self.prepare_request(req)
517
/usr/local/lib/python3.6/dist-packages/requests/sessions.py in prepare_request(self, request)
458 cookies=merged_cookies,
--> 459 hooks=merge_hooks(request.hooks, self.hooks),
460 )
/usr/local/lib/python3.6/dist-packages/requests/models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
317 self.prepare_body(data, files, json)
--> 318 self.prepare_auth(auth, url)
319
/usr/local/lib/python3.6/dist-packages/requests/models.py in prepare_auth(self, auth, url)
548 # Allow auth to make its changes.
--> 549 r = auth(self)
550
/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth1_auth.py in __call__(self, r)
108 r.url, headers, _ = self.client.sign(
--> 109 unicode(r.url), unicode(r.method), None, r.headers
110 )
/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/__init__.py in sign(self, uri, http_method, body, headers, realm)
312 request.oauth_params.append(
--> 313 ('oauth_signature', self.get_oauth_signature(request)))
314
/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/__init__.py in get_oauth_signature(self, request)
126
--> 127 uri, headers, body = self._render(request)
128
/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/__init__.py in _render(self, request, formencode, realm)
209 headers = parameters.prepare_headers(
--> 210 request.oauth_params, request.headers, realm=realm)
211 elif self.signature_type == SIGNATURE_TYPE_BODY and request.decoded_body is not None:
/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/utils.py in wrapper(params, *args, **kwargs)
31 params = filter_oauth_params(params)
---> 32 return target(params, *args, **kwargs)
33
/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/parameters.py in prepare_headers(oauth_params, headers, realm)
58 escaped_name = utils.escape(oauth_parameter_name)
---> 59 escaped_value = utils.escape(value)
60
/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/utils.py in escape(u)
56 raise ValueError('Only unicode objects are escapable. ' +
---> 57 'Got %r of type %s.' % (u, type(u)))
58 # Letters, digits, and the characters '_.-' are already treated as safe
ValueError: Only unicode objects are escapable.
Got <generator object to_unicode.. at 0x7f1a83f1cf68> of type <class 'generator'>.
During handling of the above exception, another exception occurred:
TweepError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in get_authorization_url(self, signin_with_twitter, access_type)
84 url = self._get_oauth_url('authorize')
---> 85 self.request_token = self._get_request_token(access_type=access_type)
86 return self.oauth.authorization_url(url)
/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in _get_request_token(self, access_type)
67 except Exception as e:
---> 68 raise TweepError(e)
69
TweepError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x7f1a83f1cf68> of type <class 'generator'>.
During handling of the above exception, another exception occurred:
TweepError Traceback (most recent call last)
<ipython-input-8-0d2d0c4ff837> in <module>()
1 auth = tweepy.OAuthHandler(a ,apis ,callbackurl)
----> 2 redirecurl = auth.get_authorization_url()
3 print(redirecurl)
/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in get_authorization_url(self, signin_with_twitter, access_type)
86 return self.oauth.authorization_url(url)
87 except Exception as e:
---> 88 raise TweepError(e)
89
90 def get_access_token(self, verifier=None):
TweepError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x7f1a83f1cf68> of type <class 'generator'>.
This is the code
i use google colab so i am including this
!pip install tweepy
this is all not real i have modified it
a = ["uAtzGszfcP0J1jTebtkjrgntuhvbnkuteghvk,erhnfoqi2j1289747865432565BGzfBjrjAAAAAAA"]
apis = ["rabefnO5bypwuV5KTcuS766ncZs8ctrNtrh6pJfMwDFvrwuHprtgjivruiohgbtvuhrgyuvydgfugdryehfguirdjbvyurgfy"]
b = ["AAAAAAAAAAAAAAAAAgregregergrehyrjrtksjgnyrfuykrguyrthviurjgoierghfuywehnidf3yiueghf6yregAAAAAAAAAAAL5AKgEAAAAA3wLIE6HWAXgMPcTZ8L9t1K9Lu1I%3D6SpRSXAtJF248GnzzdJ79BSyoaDMFqfPTFe8rKnxjgm5eMCQxs"]
at = ["1333671816829rehtrTNTYGBILTEJMNGUNIOERHNGVKJRHFUKERGJNVIUDFHV.NTOBN;GUONTLR8908329407837645669377-SUFHAAynfZh8DeSx3w4yVveKm5D5Ct"]
As = ["7wYChDbdN36sGf2FJSCWBEMqk65x1I7nJ4k3B#GHKJKDVHNHIUERKNVJI.UY%$VDJKRGVNEK,FVNUIDRVBKDGUH ,KER JVKUDFHBKREJVBYDIGBGKERUFVHBKJFBRKJCNzkOmfrLA"]
importing tweepy,google,time
import tweepy
import webbrowser
import time
this is also not real
callbackurl = 'oob' # https://cybemchi.000webhostapp.com/
auth = tweepy.OAuthHandler(a ,apis ,callbackurl)
redirecurl = auth.get_authorization_url()
print(redirecurl)
Problem is because you keep it as lists
a = [ "uAtz...." ]
apis = [ "rabefn..." ]
But it should be directly string
a = "uAtz...."
apis = "rabefn..."
tweepy.OAuthHandler( a, apis, ...)
Or you should use index [0] to get string from list
a = [ "uAtz...." ]
apis = [ "rabefn..." ]
tweepy.OAuthHandler( a[0], apis[0], ... )
Trying to Access a Shared Folder using the following code :
credentials = Credentials(username = user_name, password = "secret")
config = Configuration(server ='outlook.office365.com', credentials = credentials, auth_type=NTLM)
account = Account(primary_smtp_address = 'shared_mail#domain.com', credentials = credentials, autodiscover = False, config = config, access_type = DELEGATE,)
The above three lines of Code work perfectly but we are unable to get the root,
the following code : account.root.tree() or account.root throws the following error:
KeyError Traceback (most recent call last)
~\anaconda3\lib\site-packages\cached_property.py in __get__(self, obj, cls)
68 # check if the value was computed before the lock was acquired
---> 69 return obj_dict[name]
70
KeyError: 'root'
During handling of the above exception, another exception occurred:
ErrorNonExistentMailbox Traceback (most recent call last)
<ipython-input-46-a90a4f76ca21> in <module>
2 logging.basicConfig(level=logging.DEBUG)
3
----> 4 account.root.tree()
~\anaconda3\lib\site-packages\cached_property.py in __get__(self, obj, cls)
71 except KeyError:
72 # if not, do the calculation and release the lock
---> 73 return obj_dict.setdefault(name, self.func(obj))
74
75
~\anaconda3\lib\site-packages\exchangelib\account.py in root(self)
268 #threaded_cached_property
269 def root(self):
--> 270 return Root.get_distinguished(account=self)
271
272 #threaded_cached_property
~\anaconda3\lib\site-packages\exchangelib\folders\roots.py in get_distinguished(cls, account)
107 return cls.resolve(
108 account=account,
--> 109 folder=cls(account=account, name=cls.DISTINGUISHED_FOLDER_ID, is_distinguished=True)
110 )
111 except ErrorFolderNotFound:
~\anaconda3\lib\site-packages\exchangelib\folders\base.py in resolve(cls, account, folder)
485 def resolve(cls, account, folder):
486 # Resolve a single folder
--> 487 folders = list(FolderCollection(account=account, folders=[folder]).resolve())
488 if not folders:
489 raise ErrorFolderNotFound('Could not find folder %r' % folder)
~\anaconda3\lib\site-packages\exchangelib\folders\collections.py in resolve(self)
254 additional_fields = self.get_folder_fields(target_cls=self._get_target_cls(), is_complex=None)
255 for f in self.__class__(account=self.account, folders=resolveable_folders).get_folders(
--> 256 additional_fields=additional_fields
257 ):
258 yield f
~\anaconda3\lib\site-packages\exchangelib\folders\collections.py in get_folders(self, additional_fields)
317 folders=self.folders,
318 additional_fields=additional_fields,
--> 319 shape=ID_ONLY,
320 ):
321 yield f
~\anaconda3\lib\site-packages\exchangelib\services\get_folder.py in call(self, folders, additional_fields, shape)
32 **dict(
33 additional_fields=additional_fields,
---> 34 shape=shape,
35 )
36 )):
~\anaconda3\lib\site-packages\exchangelib\services\common.py in _pool_requests(self, payload_func, items, **kwargs)
538 for i, chunk in enumerate(chunkify(items, self.chunk_size), start=1):
539 log.debug('Processing %s chunk %s containing %s items', self.__class__.__name__, i, len(chunk))
--> 540 for elem in self._get_elements(payload=payload_func(chunk, **kwargs)):
541 yield elem
542
~\anaconda3\lib\site-packages\exchangelib\services\common.py in _get_elements_in_response(self, response)
401 def _get_elements_in_response(self, response):
402 for msg in response:
--> 403 container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)
404 if isinstance(container_or_exc, (bool, Exception)):
405 yield container_or_exc
~\anaconda3\lib\site-packages\exchangelib\services\common.py in _get_element_container(self, message, response_message, name)
360 # rspclass == 'Error', or 'Success' and not 'NoError'
361 try:
--> 362 raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)
363 except self.ERRORS_TO_CATCH_IN_RESPONSE as e:
364 return e
ErrorNonExistentMailbox: Mailbox does not exist.
The same code seems to be working here : https://medium.com/#theamazingexposure/accessing-shared-mailbox-using-exchangelib-python-f020e71a96ab
Also checked this thread https://github.com/ecederstrand/exchangelib/issues/391 and tried almost all the solutions but facing the same error.
I have installed elasticsearch2.1.1 in my windows machine and i have an elasticsearch index which is hosted in my machine locally as i am trying to understand it better. Name of the index is library. Below is how it looks like.
I am trying to delete the existing index using python library elasticsearch and below is the code to do so.
from elasticsearch import Elasticsearch
es = Elasticsearch('localhost:9200')
if es.indices.exists(index='library'):
es.delete('library')
When i execute this code, i end up getting below error.
---------------------------------------------------------------------------
TransportError Traceback (most recent call last)
<ipython-input-22-2a4b3642a164> in <module>()
1 from elasticsearch import Elasticsearch
2 es = Elasticsearch('localhost:9200')
----> 3 if es.indices.exists(index='library'):
4 es.delete('library')
c:\python27\lib\site-packages\elasticsearch\client\utils.pyc in _wrapped(*args, **kwargs)
71 if p in kwargs:
72 params[p] = kwargs.pop(p)
---> 73 return func(*args, params=params, **kwargs)
74 return _wrapped
75 return _wrapper
c:\python27\lib\site-packages\elasticsearch\client\indices.pyc in exists(self, index, params)
222 raise ValueError("Empty value passed for a required argument 'index'.")
223 return self.transport.perform_request('HEAD', _make_path(index),
--> 224 params=params)
225
226 #query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
c:\python27\lib\site-packages\elasticsearch\transport.pyc in perform_request(self, method, url, params, body)
310
311 try:
--> 312 status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
313
314 except TransportError as e:
c:\python27\lib\site-packages\elasticsearch\connection\http_urllib3.pyc in perform_request(self, method, url, params, body, timeout, ignore)
126 if not (200 <= response.status < 300) and response.status not in ignore:
127 self.log_request_fail(method, full_url, url, body, duration, response.status, raw_data)
--> 128 self._raise_error(response.status, raw_data)
129
130 self.log_request_success(method, full_url, url, body, response.status,
c:\python27\lib\site-packages\elasticsearch\connection\base.pyc in _raise_error(self, status_code, raw_data)
123 logger.warning('Undecodable raw error response from server: %s', err)
124
--> 125 raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
126
127
TransportError: TransportError(500, u'')
Edit: I tried as per suggestion by Slam and used below code
a = elasticsearch.client.IndicesClient('localhost:9200')
a.delete(index = 'library')
However, i am now getting a new error as follows
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-30-dc5154b36ad8> in <module>()
----> 1 a.delete(index = 'library')
c:\python27\lib\site-packages\elasticsearch\client\utils.pyc in _wrapped(*args, **kwargs)
71 if p in kwargs:
72 params[p] = kwargs.pop(p)
---> 73 return func(*args, params=params, **kwargs)
74 return _wrapped
75 return _wrapper
c:\python27\lib\site-packages\elasticsearch\client\indices.pyc in delete(self, index, params)
197 if index in SKIP_IN_PATH:
198 raise ValueError("Empty value passed for a required argument 'index'.")
--> 199 return self.transport.perform_request('DELETE', _make_path(index),
200 params=params)
201
c:\python27\lib\site-packages\elasticsearch\client\utils.pyc in transport(self)
82 #property
83 def transport(self):
---> 84 return self.client.transport
85
86 class AddonClient(NamespacedClient):
AttributeError: 'str' object has no attribute 'transport'
Elasticsearch.delete is made for deleting documents, not indexes.
To operate over idexes, you need IndicesClient.delete. Indices client is abstraction that works on top of basic ES client, with same transport. Invocation can be
>>> es = Elasticsearch('localhost:9200')
>>> es.indices.delete(index='test')
{'acknowledged': True}
My code (for the relevant part) is as follows
myactivities = []
from urllib.error import HTTPError
for activity in client.get_activities(after = activities_from, before=activities_to):
print(activity)
print(activity.id, activity.start_date)
try:
temp = client.get_activity_streams(activity.id, types=types)
except urllib.error.HTTPError:
print("HTTPError")
myactivities.append(temp)
The error print I get is this:
HTTPError Traceback (most recent call last)
<ipython-input-29-fc30cef1e4f3> in <module>()
8 try:
----> 9 temp = client.get_activity_streams(activity.id, types=types)
10 except urllib.error.HTTPError:
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in get_activity_streams(self, activity_id, types, resolution, series_type)
1174 # Pack streams into dictionary
-> 1175 return {i.type: i for i in streams}
1176
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in <dictcomp>(.0)
1174 # Pack streams into dictionary
-> 1175 return {i.type: i for i in streams}
1176
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in __next__(self)
1529 def __next__(self):
-> 1530 return self.next()
1531
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in next(self)
1535 if not self._buffer:
-> 1536 self._fill_buffer()
1537 try:
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in _fill_buffer(self)
1506
-> 1507 raw_results = self.result_fetcher(page=self._page, per_page=self.per_page)
1508
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\protocol.py in get(self, url, check_for_errors, use_webhook_server, **kwargs)
245 params = dict([(k, v) for k, v in kwargs.items() if not k in referenced])
--> 246 return self._request(url, params=params, check_for_errors=check_for_errors, use_webhook_server=use_webhook_server)
247
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\protocol.py in _request(self, url, params, files, method, check_for_errors, use_webhook_server)
169 if check_for_errors:
--> 170 self._handle_protocol_error(raw)
171
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\protocol.py in _handle_protocol_error(self, response)
214 if x is not None:
--> 215 raise x
216
HTTPError: 404 Client Error: Not Found [Record Not Found: []]
During handling of the above exception, another exception occurred:
NameError Traceback (most recent call last)
<ipython-input-29-fc30cef1e4f3> in <module>()
8 try:
9 temp = client.get_activity_streams(activity.id, types=types)
---> 10 except urllib.error.HTTPError:
11 print("HTTPError")
12 myactivities.append(temp)
NameError: name 'urllib' is not defined
How can I catch that HTTPError succesfully? I tried all the suggestions in catch specific HTTP error in python but none helped.
Try
myactivities = []
from urllib.error import HTTPError
for activity in client.get_activities(after = activities_from, before=activities_to):
print(activity)
print(activity.id, activity.start_date)
try:
temp = client.get_activity_streams(activity.id, types=types)
except HTTPError:
print("HTTPError")
myactivities.append(temp)
You already imported HTTPError, you have to use directly.
Your code shows error.
NameError Traceback (most recent call last)
<ipython-input-29-fc30cef1e4f3> in <module>()
8 try:
9 temp = client.get_activity_streams(activity.id, types=types)
---> 10 except urllib.error.HTTPError:
11 print("HTTPError")
12 myactivities.append(temp)
NameError: name 'urllib' is not defined
Which gives error because urllib is not accessible. You imported HTTPError from that.