How to fix the error in python pybliometrics.scopus.exception.Scopus401Error? - pybliometrics

I'm new to pybliometrics. I opened the python pybliometrics documentation and ran this example:
from pybliometrics.scopus import AffiliationSearch
query = "AFFIL(Max Planck Institute for Innovation and Competition Munich)"
s = AffiliationSearch(query)
print(s)
But it throws a pybliometrics.scopus.exception.Scopus401Error error.
Traceback (most recent call last):
File "C:/Users/Professional/PycharmProjects/firstScopus/main.py", line 3, in <module>
s = AffiliationSearch(query)
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\affiliation_search.py", line 106, in __init__
Search.__init__(self, query=query, api="AffiliationSearch",
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\superclasses\search.py", line 76, in __init__
Base.__init__(self, qfile, refresh, params=params, url=SEARCH_URL[api],
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\superclasses\base.py", line 70, in __init__
resp = get_content(url, params, *args, **kwds)
File "C:\Users\Professional\PycharmProjects\firstScopus\venv\lib\site-packages\pybliometrics\scopus\utils\get_content.py", line 88, in get_content
raise errors[resp.status_code](reason)
pybliometrics.scopus.exception.Scopus401Error
Process finished with exit code 1
As I understand it, I need to specify the API keys. How to do it?

You're right, according to https://pybliometrics.readthedocs.io/en/stable/access.html#error-messages 401 is most likely due to a missing key.
As the documentation on the configuration states, pybliometrics starts a process in the beginning to create the config. It asks for the API keys, and more. It seems you skipped this.
To manually create the config, go to your home directory (~/ on *nix systems) and create the folder .scopus (the dot is important). In there, create the file config.ini with a normal text editor. It needs to have at least those two sections, Directories and Authentication as shown on the documentation on the configuration.
Or simply reinstall pybliometrics and don't skip the set-up prompt in the beginning.

Related

How i resolve comunication problem opcua library with pyinstaller?

i have problem with pyinstaller i use library opcua for comunication, with normal run in pycharm everything works correctly, after create .exe with pyinstaller after few second or minute the comunication stops.
from opcua import Client
from opcua.crypto import security_policies
from opcua.ua import MessageSecurityMode
from opcua import ua
def connect(self):
try:
self.client.set_security(policy=security_policies.SecurityPolicyBasic256Sha256,
certificate_path=self.root_path+CERT_RELATIVE_PATH,
private_key_path=self.root_path+PRIVATE_KEY_RELATIVE_PATH,
mode=MessageSecurityMode.SignAndEncrypt
)
self.client.application_uri = "urn:script:opcua"
# self.client.secure_channel_timeout = 10000
self.client.session_timeout = 60000
self.client.connect()
self.root_node = self.client.get_root_node()
self.call_method('ns=2;s=/Methods/GiveUserAccess', 'OpcUaClient', 'GudWrite')
return True
except Exception:
self.main_log.info('unable to connect to nc: {}'.format(traceback.format_exc()))
raise custom_exceptions.UnableToConnect()
def get_battery_100(self):
return self.client.get_node('ns=2;s=/NC/_N_NC_GD2_ACX/DG_BATTERY_TIME').get_value()
This is the error after some data exchange:
WARNING:opcua.uaprotocol:Received an error: MessageAbort(error:StatusCode(BadSecurityChecksFailed), reason:None)
CRITICAL:opcua.client.ua_client.Socket:Received an error: MessageAbort(error:StatusCode(BadSecurityChecksFailed), reason:None)
ERROR:opcua.client.ua_client.Socket:Protocol Error
..
File "opcua\client\ua_client.py", line 101, in _run
File "opcua\client\ua_client.py", line 121, in _receive
File "opcua\client\ua_client.py", line 129, in _call_callback
opcua.ua.uaerrors._base.UaError: No future object found for request: 0, callbacks in list are dict_keys([8612, 8613])
..
..
..
File "opcua\common\node.py", line 155, in get_value
File "opcua\common\node.py", line 164, in get_data_value
File "opcua\common\node.py", line 275, in get_attribute
File "opcua\client\ua_client.py", line 347, in read
File "opcua\client\ua_client.py", line 83, in send_request
File "concurrent\futures_base.py", line 443, in result
concurrent.futures._base.CancelledError
do you know if there is any modification to make to make it work in pyinstaller for comunication0?
(class with this module is call with a thread)
BadSecurityChecksFailed related to security, are you shure you are destribute the correct certificates? Or if you are using your client on another device, are you matching the correct hostname/ipaddress in the certificates?
I solved. when i created the .exe file with pyinstaller i copied the .der and .pem certificates (all in the same pc) but if i delete them and with python I recreate them automatically, the program works correctly, instead with old certificates, the connection is unstable.

pgAdmin4 not restoring since upgrading to 4.2.2

Admittedly, I am fairly new to postgresql and pgadmin, but after spending a day learning it, with pgadmin4.4.1 I was able to backup tables and restore them in various different formats, currently, the format of choice is plain text, so that I can actually read the backup file to see what it is doing and also my database is tiny, but large enough to not want to type in every entry by hand.
Since updating to pgadmin4.4.2, the restore function does not work. I provides a green box saying restore job created, yet no data is added to the database. This was not the case yesterday, it would just restore the data.
Does anyone know what defaults might possibly have changed in the update that will be preventing my restore job from actually running? I am assuming that it is created and waiting in a queue somewhere that I can't find in order to actually run the backup.
Here is the last error from the log file. Apologies for the delay in replying.
019-02-08 17:59:06,942: ERROR pgadmin: 'NoneType' object has no attribute 'replace'
Traceback (most recent call last):
File "/Applications/pgAdmin 4.app/Contents/Resources/venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Applications/pgAdmin 4.app/Contents/Resources/venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Applications/pgAdmin 4.app/Contents/Resources/venv/lib/python3.6/site-packages/flask_login.py", line 792, in decorated_view
return func(*args, **kwargs)
File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/misc/bgprocess/__init__.py", line 61, in index
return make_response(response=BatchProcess.list())
File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/misc/bgprocess/processes.py", line 610, in list
desc = desc.message
File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/tools/backup/__init__.py", line 145, in message
port = html.safe_str(port)
File "/Applications/pgAdmin 4.app/Contents/Resources/web/pgadmin/utils/html.py", line 35, in safe_str
return cgi.escape(x)
File "/Applications/pgAdmin 4.app/Contents/Resources/venv/lib/python3.6/cgi.py", line 1056, in escape
s = s.replace("&", "&") # Must be done first!
AttributeError: 'NoneType' object has no attribute 'replace'

Smartsheet Python SDK Copy Workspace Fails

I am trying to copy a workspace to get around the 100 object limit.
Here's my code:
def rg_copy_workspace(workspace_id, new_ws_name, api_token, debug=False):
import smartsheet
smartsheet = smartsheet.Smartsheet(api_token)
smartsheet.errors_as_exceptions(True)
new_workspace = smartsheet.Workspaces.copy_workspace(
workspace_id,
smartsheet.models.ContainerDestination({
'new_name': new_ws_name
})
)
just like the example in the Python SDK.
I am testing on a workspace with a small number of objects (I started with only one Sheet)
I'm getting an error on the folder_obj. I have tried it with and without a folder, and when I have a folder with and without contents.
rg_copy_workspace(workspace_id, new_ws_name)
Traceback (most recent call last):
File "", line 1, in
rg_copy_workspace(workspace_id, new_ws_name)
File "", line 15, in rg_copy_workspace
'new_name': new_ws_name
File "(path-deleted)\workspaces.py", line 80, in copy_workspace
folder_obj = Folder({
File "(path-deleted)\smartsheet.py", line 210, in request
"""
File "(path-deleted)\smartsheet.py", line 278, in request_with_retry
if 200 <= response.status_code <= 299:
File "(path-deleted)\smartsheet.py", line 244, in _request
native = res.native(expected)
UnexpectedRequestError: (, None)
What am I doing wrong? I don't know how the code makes it to line 80 of workspaces.py.
I updated to latest version of SDK this morning (after receiving the error)
Craig
Reputation won't let me comment.
Your code seemed to execute fine for me on the updated 1.3 SDK.
The traceback locations look to lineup with sources from roughly a year ago, but linecache is pulling from the new source to build the traceback (smartsheet.py, line 210 is actually in a comment, so it's definitely not right). I'm not sure what all the situations are that could account for this but I'd guess there are compiled bytecode (.pyc) files somewhere that are stale.
Can you share a DEBUG level log near the relevant failure so that I can see what the API request looks like?

Web2py Access Control & MongoDB

I'm using MongoDB for my database.
db = DAL('mongodb://localhost:27017/app')
When I attempt to register a new user, I get the following error:
Traceback (most recent call last):
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/restricted.py", line 209, in restricted
exec ccode in environment
File "/home/ecosystem/web2py/applications/app/controllers/default.py", line 146, in <module>
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/globals.py", line 187, in <lambda>
self._caller = lambda f: f()
File "/home/ecosystem/web2py/applications/app/controllers/default.py", line 108, in user
return dict(form=auth())
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/tools.py", line 1205, in __call__
return getattr(self,args[0])()
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/tools.py", line 2180, in register
self.add_membership(group_id, form.vars.id)
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/tools.py", line 2963, in add_membership
record = membership(user_id = user_id,group_id = group_id)
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/dal.py", line 7656, in __call__
else:
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/dal.py", line 8787, in select
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/gluon/dal.py", line 5092, in select
row=[]
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/pymongo/cursor.py", line 1058, in next
if len(self.__data) or self._refresh():
File "/home/ecosystem/anaconda/lib/python2.7/site-packages/pymongo/cursor.py", line 1002, in _refresh
self.__uuid_subtype))
OverflowError: MongoDB can only handle up to 8-byte ints
If I look in my database tables, everything seems okay except a couple fields.
In auth_user (not sure about this one):
registration_id:""
In auth_event (I'm assuming this should not be null):
user_id:null
What is the best way to resolve this? If possible, I'd like to use MongoDB for all database transactions (including access control / authentication).
UPDATE: You can avoid this by upgrading to the latest version of Web2py. This is now fully supported so you do not need to use two different databases.
I wasn't able to solve this problem directly, but I was able to create a work-around. In db.py, I define two separate database connections:
db = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all'])
db1 = DAL('mongodb://localhost:27017/collection')
I call db (eventually a mysql database) on all auth functions (registration, login, is logged in checks), while handling everything else (including detailed member profiles) in mongo. I often bypass db1 DAL entirely by using the pymongo API.

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. tastypie

Continuing my search for an answer to get oauth2.0 to work on pythonanywhere.
i am following this tutorial: http://ianalexandr.com/blog/building-a-true-oauth-20-api-with-django-and-tasty-pie.html
im using django 1.6 : https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango
when i get to this line of codes:
from provider.oauth2.models import Client
# from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
User = get_user_model()
u = User.objects.get(id=1)
c = Client(user=u, name="mysite client", client_type=1, url="http://pythonx00x.pythonanywhere.com")
c.save()
c.client_id
'd63f53a7a6cceba04db5'
c.client_secret
'afe899288b9ac4127d57f2f12ac5a49d839364dc'
it seems that i got an error at line:
User = get_user_model()
and it raise an error:
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
here is the full stack trace:
Traceback (most recent call last):
File "addClient.py", line 9, in <module>
User = get_user_model()
File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/apps/registry.py", line 200, in get_model
self.check_models_ready()
File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/apps/registry.py", line 132, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I can't seem to find out how to get the models load.
if I'm getting the idea right.
I think you may not be using the version of Django that you think you are. AppRegistryNotReady was introduced in Django 1.7. I would guess that, if you pinned your DJango version to 1.6, your code would work.