I am using ipwhois for the first time. Running the basic usage example with a Google IP address works:
from ipwhois import IPWhois
obj = IPWhois('74.125.225.229')
results = obj.lookup_rdap(depth=1)
Any other IP address results in this error:
ASNRegistryError Traceback (most recent call last)
<ipython-input-62-03afc25be9cd> in <module>()
----> 1 results = obj.lookup_rdap(depth=1)
~\_installed\anaconda\envs\geocode\lib\site-packages\ipwhois\ipwhois.py in lookup_rdap(self, inc_raw, retry_count, depth, excluded_entities, bootstrap, rate_limit_timeout, asn_alts, extra_org_map, inc_nir, nir_field_list, asn_methods, get_asn_description)
306 inc_raw=inc_raw, retry_count=retry_count, asn_alts=asn_alts,
307 extra_org_map=extra_org_map, asn_methods=asn_methods,
--> 308 get_asn_description=get_asn_description
309 )
310
~\_installed\anaconda\envs\geocode\lib\site-packages\ipwhois\asn.py in lookup(self, inc_raw, retry_count, asn_alts, extra_org_map, asn_methods, get_asn_description)
569 if asn_data is None:
570
--> 571 raise ASNRegistryError('ASN lookup failed with no more methods to '
572 'try.')
573
ASNRegistryError: ASN lookup failed with no more methods to try.
I attempted to switch the lookup method to ARIN with bootstrap=True to no avail. How do I remedy this error?
Related
I need to connect to a LDAP server using Python (Version 3.8.8) and I've already tried to replicate some examples such as those showed in the link bellow but none of them are working for me. I either get (TypeError: iter() returned non-iterator of type 'NoneType') or (PyAsn1Error: Attempted "__iter__" operation on ASN.1 schema object). It seems like ldap3 and python-ldap used in the examples were not updated to work with python 3.8.8. I would be very pleased if anyone could give me a real example of another existing library to connect a LPDAP server or help me with this issue.
(1) https://sixfeetup.com/blog/new-ldap3-python-ldap-library
(2) https://ldap3.readthedocs.io/en/latest/tutorial_intro.html
(3) https://stackoverflow.com/questions/58907026/ldap3-bind-failed-when-cn-and-displayname-are-different
my test error for the example in link 3:
from ldap3 import Server, Connection
server = Server('ipa.demo1.freeipa.org')
conn = Connection(server)
conn.bind()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
ipython-input-4-470896b147da> in <module>
2 server = Server('ipa.demo1.freeipa.org')
3 conn = Connection(server)
----> 4 conn.bind()
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\core\connection.py in bind(self, read_server_info, controls)
418 if log_enabled(PROTOCOL):
419 log(PROTOCOL, 'anonymous BIND request <%s> sent via <%s>', bind_request_to_dict(request), self)
--> 420 response = self.post_send_single_response(self.send('bindRequest', request, controls))
421 elif self.authentication == SIMPLE:
422 if log_enabled(PROTOCOL):
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\strategy\sync.py in post_send_single_response(self, message_id)
120 Returns the result message or None
121 """
--> 122 responses, result = self.get_response(message_id)
123 self.connection.result = result
124 if result['type'] == 'intermediateResponse': # checks that all responses are intermediates (there should be only one)
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\strategy\base.py in get_response(self, message_id, timeout)
296 if self._outstanding and message_id in self._outstanding:
297 while timeout >= 0: # waiting for completed message to appear in responses
--> 298 responses = self._get_response(message_id)
299 if not responses:
300 sleep(RESPONSE_SLEEPTIME)
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\strategy\sync.py in _get_response(self, message_id)
166 log(EXTENDED, 'ldap message received via <%s>:%s', self.connection, format_ldap_message(ldap_resp, '<<'))
167 if int(ldap_resp['messageID']) == message_id:
--> 168 dict_response = self.decode_response(ldap_resp)
169 ldap_responses.append(dict_response)
170 if dict_response['type'] not in ['searchResEntry', 'searchResRef', 'intermediateResponse']:
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\strategy\base.py in decode_response(self, ldap_message)
401 if message_type == 'bindResponse':
402 if not bytes(component['matchedDN']).startswith(b'NTLM'): # patch for microsoft ntlm authentication
--> 403 result = bind_response_to_dict(component)
404 else:
405 result = sicily_bind_response_to_dict(component)
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\operation\bind.py in bind_response_to_dict(response)
116 'dn': str(response['matchedDN']),
117 'message': str(response['diagnosticMessage']),
--> 118 'referrals': referrals_to_list(response['referral']),
119 'saslCreds': bytes(response['serverSaslCreds']) if response['serverSaslCreds'] is not None else None}
120
C:\ProgramData\Anaconda3\lib\site-packages\ldap3\protocol\convert.py in referrals_to_list(referrals)
42
43 def referrals_to_list(referrals):
---> 44 return [str(referral) for referral in referrals if referral] if referrals else None
45
46
C:\ProgramData\Anaconda3\lib\site-packages\pyasn1\type\base.py in __bool__(self)
572 else:
573 def __bool__(self):
--> 574 return bool(self.components)
575
576 #property
C:\ProgramData\Anaconda3\lib\site-packages\pyasn1\type\univ.py in components(self)
1958 def components(self):
1959 return [self._componentValues[idx]
-> 1960 for idx in sorted(self._componentValues)]
1961
1962 def clear(self):
TypeError: iter() returned non-iterator of type 'NoneType'
It was a problem of library version... I ran the "pip install ldap3 upgrade" command and it worked fine
yahoo_finance's get_historical function has been working fine for me until yesterday.
Now it just keeps giving me YQLResponseMalformedError every time I try to call get_historical. Any ideas? I literally did nothing new with the code.
from yahoo_finance import Share
yahoo = Share('YHOO')
yahoo.refresh()
yahoo.get_historical('2014-04-26', '2014-04-29')
---------------------------------------------------------------------------
YQLResponseMalformedError Traceback (most recent call last)
<ipython-input-8-fbc20f9b6d26> in <module>()
----> 1 yahoo.get_historical('2014-04-26', '2014-04-29')
/Users/anjian/anaconda/lib/python2.7/site-packages/yahoo_finance-1.4.0-py2.7.egg/yahoo_finance/__init__.pyc in get_historical(self, start_date, end_date)
340 try:
341 query = self._prepare_query(table='historicaldata', startDate=s, endDate=e)
--> 342 result = self._request(query)
343 if isinstance(result, dict):
344 result = [result]
/Users/anjian/anaconda/lib/python2.7/site-packages/yahoo_finance-1.4.0-py2.7.egg/yahoo_finance/__init__.pyc in _request(self, query)
123 raise YQLQueryError(response['error']['description'])
124 except KeyError:
--> 125 raise YQLResponseMalformedError()
126 else:
127 if self._is_error_in_results(results):
YQLResponseMalformedError: Response malformed.
Answered here: Python and Yahoo finance weird "YQLQueryError(response['error']['description'])" get_historical
I'm trying to learn how to use the Azure Table Storage service. I'm following this tutorial: https://learn.microsoft.com/en-us/azure/storage/storage-python-how-to-use-table-storage and I am simply copy pasting the code into a jupyter notebook. I've setup a storage account and am successfully using the blob storage. Also from a notebook.
Code from the tutorial:
from azure.storage.table import TableService, Entity
table_service = TableService(account_name='myaccount', account_key='mykey')
table_service.create_table('tasktable')
When I run the last line I get the following error and I'm not sure what I am doing wrong to cause it
---------------------------------------------------------------------------
Error Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/azure/storage/storageclient.py in _perform_request(self, request, parser, parser_args, operation_context)
205 _add_date_header(request)
--> 206 self.authentication.sign_request(request)
207
/usr/local/lib/python3.5/site-packages/azure/storage/_auth.py in sign_request(self, request)
96
---> 97 self._add_authorization_header(request, string_to_sign)
98
/usr/local/lib/python3.5/site-packages/azure/storage/_auth.py in _add_authorization_header(self, request, string_to_sign)
50 def _add_authorization_header(self, request, string_to_sign):
---> 51 signature = _sign_string(self.account_key, string_to_sign)
52 auth_string = 'SharedKey ' + self.account_name + ':' + signature
/usr/local/lib/python3.5/site-packages/azure/storage/_common_conversion.py in _sign_string(key, string_to_sign, key_is_base64)
87 if key_is_base64:
---> 88 key = _decode_base64_to_bytes(key)
89 else:
/usr/local/lib/python3.5/site-packages/azure/storage/_common_conversion.py in _decode_base64_to_bytes(data)
77 data = data.encode('utf-8')
---> 78 return base64.b64decode(data)
79
/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/base64.py in b64decode(s, altchars, validate)
89 raise binascii.Error('Non-base64 digit found')
---> 90 return binascii.a2b_base64(s)
91
Error: Incorrect padding
During handling of the above exception, another exception occurred:
AzureException Traceback (most recent call last)
<ipython-input-17-192b23ba629f> in <module>()
----> 1 table_service.create_table('tasktable')
/usr/local/lib/python3.5/site-packages/azure/storage/table/tableservice.py in create_table(self, table_name, fail_on_exist, timeout)
520 if not fail_on_exist:
521 try:
--> 522 self._perform_request(request)
523 return True
524 except AzureHttpError as ex:
/usr/local/lib/python3.5/site-packages/azure/storage/table/tableservice.py in _perform_request(self, request, parser, parser_args, operation_context)
1087 def _perform_request(self, request, parser=None, parser_args=None, operation_context=None):
1088 _update_storage_table_header(request)
-> 1089 return super(TableService, self)._perform_request(request, parser, parser_args, operation_context)
/usr/local/lib/python3.5/site-packages/azure/storage/storageclient.py in _perform_request(self, request, parser, parser_args, operation_context)
264 sleep(retry_interval)
265 else:
--> 266 raise ex
267 finally:
268 # If this is a location locked operation and the location is not set,
/usr/local/lib/python3.5/site-packages/azure/storage/storageclient.py in _perform_request(self, request, parser, parser_args, operation_context)
240 if sys.version_info >= (3,):
241 # Automatic chaining in Python 3 means we keep the trace
--> 242 raise AzureException(ex.args[0])
243 else:
244 # There isn't a good solution in 2 for keeping the stack trace
AzureException: Incorrect padding
As a summary, the issue was caused by the variable name for account key within some mistake. Accroding to the error information Error: Incorrect padding, as #Scovetta said, it seems to be not BASE64 encoding. Some changes for the key like missing the last = symbol or adding more = symbol will cause the error. And the length of correct account key of Azure Storage is 88.
Shameless necro after putting "incorrect padding azure" in my favorite search engine.
Turns out I was passing arguments like so : --account-key "$ACCOUNT_KEY", and Azure didn't understand the quotes.
Since it's supposed to be base64 encoded, all characters in there should be shell-safe, so if your input is OK there shouldn't be any problem putting it like that.
The current analytical workspace code seems to have some import error.
I tried this ..
from cubes import Workspace
workspace = Workspace(config="slicer.ini")
workspace.import_model("model.json")
workspace.list_cubes()
And I get this error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-f80f0974af47> in <module>()
----> 1 workspace.list_cubes()
/home/anand/.virtualenvs/cubes/local/lib/python2.7/site-packages/cubes/workspace.pyc in list_cubes(self, identity)
535 """
536
--> 537 all_cubes = self.namespace.list_cubes(recursive=True)
538
539 if self.authorizer:
/home/anand/.virtualenvs/cubes/local/lib/python2.7/site-packages/cubes/namespace.pyc in list_cubes(self, recursive)
112 name = cube["name"]
113 if name in cube_names:
--> 114 raise ModelError("Duplicate cube '%s'" % name)
115 cube_names.add(name)
116
NameError: global name 'ModelError' is not defined
I'm using the 1.0.1 version.
And have tried the latest master from github, but that fails even at the
from cubes import Workspace
I am unable to do any writes to a remote mongodb database. I am able to connect and do lookups (e.g. find). I connect like this:
conn = pymongo.MongoClient(db_uri,slaveOK=True)
db = conn.test_database
coll = db.test_collection
But when I try to insert,
coll.insert({'a':1})
I run into an error:
---------------------------------------------------------------------------
AutoReconnect Traceback (most recent call last)
<ipython-input-56-d4ffb9e3fa79> in <module>()
----> 1 coll.insert({'a':1})
/usr/lib/python2.7/dist-packages/pymongo/collection.pyc in insert(self, doc_or_docs, manipulate, safe, check_keys, continue_on_error, **kwargs)
410 message._do_batched_insert(self.__full_name, gen(), check_keys,
411 safe, options, continue_on_error,
--> 412 self.uuid_subtype, client)
413
414 if return_one:
/usr/lib/python2.7/dist-packages/pymongo/mongo_client.pyc in _send_message(self, message, with_last_error, command, check_primary)
1126 except (ConnectionFailure, socket.error), e:
1127 self.disconnect()
-> 1128 raise AutoReconnect(str(e))
1129 except:
1130 sock_info.close()
AutoReconnect: not master
If I remove the slaveOK=True (setting it to it's default value of False) then I can still connect, but the reads (and writes) fail:
AutoReconnect Traceback (most recent call last)
<ipython-input-70-6671eea24f80> in <module>()
----> 1 coll.find_one()
/usr/lib/python2.7/dist-packages/pymongo/collection.pyc in find_one(self, spec_or_id, *args, **kwargs)
719 *args, **kwargs).max_time_ms(max_time_ms)
720
--> 721 for result in cursor.limit(-1):
722 return result
723 return None
/usr/lib/python2.7/dist-packages/pymongo/cursor.pyc in next(self)
1036 raise StopIteration
1037 db = self.__collection.database
-> 1038 if len(self.__data) or self._refresh():
1039 if self.__manipulate:
1040 return db._fix_outgoing(self.__data.popleft(),
/usr/lib/python2.7/dist-packages/pymongo/cursor.pyc in _refresh(self)
980 self.__skip, ntoreturn,
981 self.__query_spec(), self.__fields,
--> 982 self.__uuid_subtype))
983 if not self.__id:
984 self.__killed = True
/usr/lib/python2.7/dist-packages/pymongo/cursor.pyc in __send_message(self, message)
923 self.__tz_aware,
924 self.__uuid_subtype,
--> 925 self.__compile_re)
926 except CursorNotFound:
927 self.__killed = True
/usr/lib/python2.7/dist-packages/pymongo/helpers.pyc in _unpack_response(response, cursor_id, as_class, tz_aware, uuid_subtype, compile_re)
99 error_object = bson.BSON(response[20:]).decode()
100 if error_object["$err"].startswith("not master"):
--> 101 raise AutoReconnect(error_object["$err"])
102 elif error_object.get("code") == 50:
103 raise ExecutionTimeout(error_object.get("$err"),
AutoReconnect: not master and slaveOk=false
Am I connecting incorrectly? Is there a way to specify connecting to the primary replica?
AutoReconnect: not master means that your operation is failing because the node on which you are attempting to issue the command is not the primary of a replica set, where the command (e.g., a write operation) requires that node to be a primary. Setting slaveOK=True just enables you to read from a secondary node, where by default you would only be able to read from the primary.
MongoClient is automatically able to discover and connect to the primary if the replica set name is provided to the constructor with replicaSet=<replica set name>. See "Connecting to a Replica Set" in the PyMongo docs.
As an aside, slaveOK is deprecated, replaced by ReadPreference. You can specify a ReadPreference when creating the client or when issuing queries, if you want to target a node other than the primary.
I don't know It's related to this topic or not But when I searched about the below exception google leads me to the question. Maybe it'd be helpful.
pymongo.errors.NotMasterError: not master
In my case, My hard drive was full.
you can also figure it out with df -h command