Cura/cura/UltimakerCloud/UltimakerCloudScope.py
Ghostkeeper df69d543a2
Not logged in for API calls is not a warning
Many requests are made without being logged in, such as to get the list of plug-ins when opening the Marketplace.

Contributes to issue CURA-7501.
2020-10-16 14:15:18 +02:00

31 lines
1.1 KiB
Python

from PyQt5.QtNetwork import QNetworkRequest
from UM.Logger import Logger
from UM.TaskManagement.HttpRequestScope import DefaultUserAgentScope
from cura.API import Account
from cura.CuraApplication import CuraApplication
class UltimakerCloudScope(DefaultUserAgentScope):
"""
Add an Authorization header to the request for Ultimaker Cloud Api requests, if available.
Also add the user agent headers (see DefaultUserAgentScope).
"""
def __init__(self, application: CuraApplication):
super().__init__(application)
api = application.getCuraAPI()
self._account = api.account # type: Account
def requestHook(self, request: QNetworkRequest):
super().requestHook(request)
token = self._account.accessToken
if not self._account.isLoggedIn or token is None:
Logger.debug("User is not logged in for Cloud API request to {url}".format(url = request.url().toDisplayString()))
return
header_dict = {
"Authorization": "Bearer {}".format(token)
}
self.addHeaders(request, header_dict)