The following python code got error when creating an instance of KafkaAdminClient.
from kafka.admin import KafkaAdminClient, NewTopic
admin_client = KafkaAdminClient(
bootstrap_servers=bootstrap_servers,
client_id='test',
security_protocol="SSL"
)
got the following error:
---------------------------------------------------------------------------
KafkaConnectionError Traceback (most recent call last)
<ipython-input-10-edd53455dcb0> in <module>()
4 admin_client = KafkaAdminClient(
5 bootstrap_servers=bootstrap_servers,
----> 6 client_id='test', security_protocol="SSL"
7 )
8
/apps/external/4/anaconda3/lib/python3.6/site-packages/kafka/admin/client.py in __init__(self, **configs)
216
217 self._closed = False
--> 218 self._refresh_controller_id()
219 log.debug("KafkaAdminClient started.")
220
/apps/external/4/anaconda3/lib/python3.6/site-packages/kafka/admin/client.py in _refresh_controller_id(self)
271 future = self._send_request_to_node(self._client.least_loaded_node(), request)
272
--> 273 self._wait_for_futures([future])
274
275 response = future.value
/apps/external/4/anaconda3/lib/python3.6/site-packages/kafka/admin/client.py in _wait_for_futures(self, futures)
1340
1341 if future.failed():
-> 1342 raise future.exception # pylint: disable-msg=raising-bad-type
KafkaConnectionError: KafkaConnectionError: socket disconnected
However, the following code runs without any error.
from kafka import KafkaConsumer
consumer = KafkaConsumer(
group_id='test',
bootstrap_servers=bootstrap_servers,
security_protocol="SSL")
print(consumer.topics())
Related
I'm trying to access trino via python and I keep getting the error below. This is to access the trino interface and retrieve data from oracle. Please advise on how this can be resolved.
HttpError Traceback (most recent call last)
/tmp/ipykernel_166/2315044439.py in <module>
10 )
11 cur = conn.cursor()
---> 12 cur.execute('SELECT * FROM system.runtime.nodes')
13 rows = cur.fetchall()
14 print(cur)
~/.local/lib/python3.9/site-packages/trino/dbapi.py in execute(self, operation, params)
394 else:
395 self._query = trino.client.TrinoQuery(self._request, sql=operation)
--> 396 result = self._query.execute()
397 self._iterator = iter(result)
398 return result
~/.local/lib/python3.9/site-packages/trino/client.py in execute(self, additional_http_headers)
505
506 response = self._request.post(self._sql, additional_http_headers)
--> 507 status = self._request.process(response)
508 self.query_id = status.id
509 self._stats.update({"queryId": self.query_id})
~/.local/lib/python3.9/site-packages/trino/client.py in process(self, http_response)
382 def process(self, http_response) -> TrinoStatus:
383 if not http_response.ok:
--> 384 self.raise_response_error(http_response)
385
386 http_response.encoding = "utf-8"
~/.local/lib/python3.9/site-packages/trino/client.py in raise_response_error(self, http_response)
373 raise exceptions.Http503Error("error 503: service unavailable")
374
--> 375 raise exceptions.HttpError(
376 "error {}{}".format(
377 http_response.status_code,
HttpError: error 401: b'Unknown signing key ID' ```
I use a jupyter notebook and run twint.
Code
c = twint.Config()
c.Username = 'twitter'
c.Limit = 20
twint.run.Followers(c)
The above commands produce a runtime error relating to (I believe) the code attempting to create 2 asynchronous event loops.
Traceback as follows:
RuntimeError Traceback (most recent call last)
<ipython-input-4-4713cc05fb59> in <module>()
----> 1 twint.run.Favorites(c)
~/coding/tools/twint/twint/run.py in Favorites(config)
119 def Favorites(config):
120 config.Favorites = True
--> 121 run(config)
122
123 def Followers(config):
~/coding/tools/twint/twint/run.py in run(config)
115
116 def run(config):
--> 117 get_event_loop().run_until_complete(Twint(config).main())
118
119 def Favorites(config):
~/.pyenv/versions/3.6.5/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
453 future.add_done_callback(_run_until_complete_cb)
454 try:
--> 455 self.run_forever()
456 except:
457 if new_task and future.done() and not future.cancelled():
~/.pyenv/versions/3.6.5/lib/python3.6/asyncio/base_events.py in run_forever(self)
407 self._check_closed()
408 if self.is_running():
--> 409 raise RuntimeError('This event loop is already running')
410 if events._get_running_loop() is not None:
411 raise RuntimeError(
RuntimeError: This event loop is already running
I have found a solution for Jupyter notebooks
using the nest_async
Simply do
pip install nest_asyncio
And add these lines.
import nest_asyncio
nest_asyncio.apply()
I am getting this error after I am running:
(100*df.isna().sum()/df.shape[0]).round(1)
I use Jupyter (Anaconda).
This is the full error i get:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-20-e4ddd4ac043f> in <module>
----> 1 (100*df.isna().sum()/df.shape[0]).round(1)
~\Anaconda3\lib\site-packages\pandas\core\ops\__init__.py in wrapper(left, right)
1046
1047 with np.errstate(all="ignore"):
-> 1048 result = na_op(lvalues, rvalues)
1049 return construct_result(
1050 left, result, index=left.index, name=res_name, dtype=None
~\Anaconda3\lib\site-packages\pandas\core\ops\__init__.py in na_op(x, y)
963 TypeError : invalid operation
964 """
--> 965 import pandas.core.computation.expressions as expressions
966
967 try:
~\Anaconda3\lib\site-packages\pandas\core\computation\expressions.py in <module>
17 from pandas.core.dtypes.generic import ABCDataFrame
18
---> 19 from pandas.core.computation.check import _NUMEXPR_INSTALLED
20
21 if _NUMEXPR_INSTALLED:
~\Anaconda3\lib\site-packages\pandas\core\computation\check.py in <module>
1 from pandas.compat._optional import import_optional_dependency
2
----> 3 ne = import_optional_dependency("numexpr", raise_on_missing=False, on_version="warn")
4 _NUMEXPR_INSTALLED = ne is not None
5 if _NUMEXPR_INSTALLED:
~\Anaconda3\lib\site-packages\pandas\compat\_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
97 minimum_version = VERSIONS.get(name)
98 if minimum_version:
---> 99 version = _get_version(module)
100 if distutils.version.LooseVersion(version) < minimum_version:
101 assert on_version in {"warn", "raise", "ignore"}
~\Anaconda3\lib\site-packages\pandas\compat\_optional.py in _get_version(module)
46
47 if version is None:
---> 48 raise ImportError("Can't determine version for {}".format(module.__name__))
49 return version
50
ImportError: Can't determine version for numexpr
It started just after I had updated my scikit-learn.
I tried this , And I still have this problem. What can I do in order to fix it?
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)
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.