Issue during import, MLRunNotFoundError - python

I installed python package MLRun correctly, but I got in jupyter this error
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/mlrun/errors.py in raise_for_status(response, message)
75 try:
---> 76 response.raise_for_status()
77 except requests.HTTPError as exc:
/opt/conda/lib/python3.8/site-packages/requests/models.py in raise_for_status(self)
942 if http_error_msg:
--> 943 raise HTTPError(http_error_msg, response=self)
944
HTTPError: 404 Client Error: Not Found for url: https://mlrun-api.default-tenant.app.iguazio.prod//api/v1/client-spec
...
/opt/conda/lib/python3.8/site-packages/mlrun/errors.py in raise_for_status(response, message)
80 error_message = f"{str(exc)}: {message}"
81 try:
---> 82 raise STATUS_ERRORS[response.status_code](
83 error_message, response=response
84 ) from exc
MLRunNotFoundError: 404 Client Error: Not Found for url: https://mlrun-api.default-tenant.app.iguazio.prod//api/v1/client-spec: details: Not Found
based on this source code in python:
%pip install mlrun scikit-learn~=1.0
import mlrun
...
Do you see issues?
BTW: I installed relevant MLRun version (the same as on server side). I modified file mlrun.env and added values for these variables MLRUN_DBPATH, V3IO_USERNAME, V3IO_ACCESS_KEY

Issue
I got it, the problem is in invalid url, see error message Not Found for url: https://mlrun-api.default-tenant.app.iguazio.prod//api/v1/client-spec.
You can see double // and it is the issue, variable MLRUN_DB contains this url 'https://mlrun-api.default-tenant.app.iguazio.prod/'.
Solution
You have to remove end / in MLRUN_DB and final value will be MLRUN_DB=https://mlrun-api.default-tenant.app.iguazio.prod
Now it works.

Related

Django getting error exceptions must derive from BaseException

Info: I want to upload files using Uppy in frontend and django-tus as backend for file processing. I am getting error TypeError: exceptions must derive from BaseException.
Traceback
Internal Server Error: /tus/upload/6393bfe5-277e-4c68-b9af-c0394be796b9
Traceback (most recent call last):
File "/django_tus/tusfile.py", line 75, in get_tusfile_or_404
raise TusResponse(status=404)
TypeError: exceptions must derive from BaseException
[06/Aug/2022 14:36:42] "HEAD /tus/upload/6393bfe5-277e-4c68-b9af-c0394be796b9 HTTP/1.1" 500 103054
[06/Aug/2022 14:36:42,624] - Broken pipe from ('127.0.0.1', 35814)
[06/Aug/2022 14:36:42] "POST /tus/upload/ HTTP/1.1" 201 0
[06/Aug/2022 14:36:42] "PATCH /tus/upload/8295bef4-c94a-4ab7-9c75-2635c74428d8 HTTP/1.1" 204 0
https://github.com/alican/django-tus/blob/master/django_tus/tusfile.py
class TusUpload(View):
def head(self, request, resource_id):
tus_file = TusFile.get_tusfile_or_404(str(resource_id))
return TusResponse(
status=200,
extra_headers={
'Upload-Offset': tus_file.offset,
'Upload-Length': tus_file.file_size,
})
def create_initial_file(metadata, file_size: int):
resource_id = str(uuid.uuid4())
cache.add("tus-uploads/{}/filename".format(resource_id), "{}".format(metadata.get("filename")), settings.TUS_TIMEOUT)
cache.add("tus-uploads/{}/file_size".format(resource_id), file_size, settings.TUS_TIMEOUT)
cache.add("tus-uploads/{}/offset".format(resource_id), 0, settings.TUS_TIMEOUT)
cache.add("tus-uploads/{}/metadata".format(resource_id), metadata, settings.TUS_TIMEOUT)
tus_file = TusFile(resource_id)
tus_file.write_init_file()
return tus_file
EDIT: Our pull request has now fixed this error.
The django-tus attempts in case of 404 error raise in line 60 TusResponse which does not however inherit from exception.
This is an error of the library. It has not been updated in 2 years and according to the #torek BaseException inheritance was not previously enforced. You could try to wrap it in try-except with TypeError but in my implementation this does not work.
You could attempt to add BaseException to inherited classes of TusResponse in your version of django-tus.
class TusResponse(HttpResponse, BaseException):
which should remove the error.

pd.read_html works in Microsoft Edge but not in Chrome

This simple code works in Microsoft Edge but not in Chrome (both using Jupyter):
import pandas as pd
url_Chelsea = "https://en.wikipedia.org/wiki/List_of_Chelsea_F.C._seasons"
df_Chelsea=pd.read_html(url_Chelsea)[2]
df_Chelsea
getting the error message (end of message):
/opt/conda/lib/python3.6/site-packages/pandas/compat/__init__.py in raise_with_traceback(exc, traceback)
338 if traceback == Ellipsis:
339 _, _, traceback = sys.exc_info()
--> 340 raise exc.with_traceback(traceback)
341 else:
342 # this version of raise is a syntax error in Python 3
URLError: <urlopen error Tunnel connection failed: 403 Forbidden>
Try this :
import pandas as pd
import requests
url_Chelsea = "https://en.wikipedia.org/wiki/List_of_Chelsea_F.C._seasons"
proxyDict = {
'http' : "add http proxy",
'https' : "add https proxy"
}
requests.get(url_Chelsea , proxies=proxyDict)
df_Chelsea=pd.read_html(page)[2]
print(df_Chelsea)
For more information about proxies visit here

Running into error for google translation of data

I am attempting to translate a list of tweets with the following sample code:
from google_trans_new import google_translator
translator = google_translator()
translate_text = translator.translate('สวัสดีจีน', lang_src='th',lang_tgt='en')
print(translate_text)
I keep running into the following long error when I run the code:
HTTPError Traceback (most recent call last)
~\anaconda3\lib\site-packages\google_trans_new\google_trans_new.py in translate(self, text, lang_tgt, lang_src, pronounce)
188 raise e
--> 189 r.raise_for_status()
190 except requests.exceptions.ConnectTimeout as e:
~\anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
940 if http_error_msg:
--> 941 raise HTTPError(http_error_msg, response=self)
942
HTTPError: 429 Client Error: Too Many Requests for url: https://www.google.com/sorry/index?continue=https://translate.google.cn/_/TranslateWebserverUi/data/batchexecute&q=EgRrvwCgGLHwuIAGIhkA8aeDS9RXYOujcLlE7r1EY3pCFB3PU57xMgFy
During handling of the above exception, another exception occurred:
google_new_transError Traceback (most recent call last)
<ipython-input-1-e0a80cf9e6cc> in <module>
1 from google_trans_new import google_translator
2 translator = google_translator()
----> 3 translate_text = translator.translate('สวัสดีจีน', lang_src='th',lang_tgt='en')
4 print(translate_text)
5 #output: Hello china
~\anaconda3\lib\site-packages\google_trans_new\google_trans_new.py in translate(self, text, lang_tgt, lang_src, pronounce)
192 except requests.exceptions.HTTPError as e:
193 # Request successful, bad response
--> 194 raise google_new_transError(tts=self, response=r)
195 except requests.exceptions.RequestException as e:
196 # Request failed
google_new_transError: 429 (Too Many Requests) from TTS API. Probable cause: Unknown
Is this because I have used the translator too frequently? When will it reset so I can continue my work?
google_trans_new is an unofficial library using the web API of translate.google.com and also is not associated with Google.
It is crawling the translate web page, which is why you eventually received a 429 error message which is the HTTP 429 Too Many Request status code.
These kind of unofficial libraries are unstable and will eventually get blocked.
To get a stable application you should use the official library which calls the Cloud Translation API.
The Cloud Translation API has quotas but it takes care of handling these errors with retries using exponential backoff.

IBM text to speech Python DecodeError

I just tried the basic example of IBM's text to speech with Python:
!pip install ibm_watson
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
apikey = 'my API KEY'
url = 'my SERVICE URL'
authenticator = IAMAuthenticator(apikey)
tts = TextToSpeechV1(authenticator=authenticator)
tts.set_service_url(url)
with open('./speech.mp3', 'wb') as audio_file:
res = tts.synthesize('Hello World!', accept='audio/mp3', voice='en-US_AllisonV3Voice').get_result()
audio_file.write(res.content)
But I get an error message:
DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode().*
DecodeError Traceback (most recent call last)
<ipython-input-5-53b9d398591b> in <module>
1 with open('./speech.mp3', 'wb') as audio_file:
----> 2 res = tts.synthesize('Hello World!', accept='audio/mp3', voice='en-US_AllisonV3Voice').get_result()
3 audio_file.write(res.content)
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\ibm_watson\text_to_speech_v1.py in synthesize(self, text, accept, voice, customization_id, **kwargs)
275
276 url = '/v1/synthesize'
--> 277 request = self.prepare_request(method='POST',
278 url=url,
279 headers=headers,
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\ibm_cloud_sdk_core\base_service.py in prepare_request(self, method, url, headers, params, data, files, **kwargs)
295 request['data'] = data
296
--> 297 self.authenticator.authenticate(request)
298
299 # Next, we need to process the 'files' argument to try to fill in
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\ibm_cloud_sdk_core\authenticators\iam_authenticator.py in authenticate(self, req)
104 """
105 headers = req.get('headers')
--> 106 bearer_token = self.token_manager.get_token()
107 headers['Authorization'] = 'Bearer {0}'.format(bearer_token)
108
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\ibm_cloud_sdk_core\jwt_token_manager.py in get_token(self)
77 """
78 if self._is_token_expired():
---> 79 self.paced_request_token()
80
81 if self._token_needs_refresh():
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\ibm_cloud_sdk_core\jwt_token_manager.py in paced_request_token(self)
122 if not request_active:
123 token_response = self.request_token()
--> 124 self._save_token_info(token_response)
125 self.request_time = 0
126 return
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\ibm_cloud_sdk_core\jwt_token_manager.py in _save_token_info(self, token_response)
189
190 # The time of expiration is found by decoding the JWT access token
--> 191 decoded_response = jwt.decode(access_token, verify=False)
192 # exp is the time of expire and iat is the time of token retrieval
193 exp = decoded_response.get('exp')
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\jwt\api_jwt.py in decode(self, jwt, key, algorithms, options, **kwargs)
111 **kwargs,
112 ) -> Dict[str, Any]:
--> 113 decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
114 return decoded["payload"]
115
c:\users\chris\appdata\local\programs\python\python39\lib\site-packages\jwt\api_jwt.py in decode_complete(self, jwt, key, algorithms, options, **kwargs)
77
78 if options["verify_signature"] and not algorithms:
---> 79 raise DecodeError(
80 'It is required that you pass in a value for the "algorithms" argument when calling decode().'
81 )
DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode().
The issue may be with the newest version of PyJWT package (2.0.0).
use
pip install PyJWT==1.7.1
to downgrade to the previous version and your project may work now. ( this worked for me )
Yea there is definitely an issue with pyjwt > 2.0, like earlier mentioned you need to uninstall the previous version and install a more stable one like 1.7.1.
it worked for me
I was having this problem with PyJWT==2.1.0,
My existing code,
import jwt
data = 'your_data'
key = 'your_secret_key'
encoded_data = jwt.encode(data, key) # worked
decoded_data = jwt.decode(encoded_data, key) # did not worked
I passed the algorithm for encoding and afterwards it worked fine,
Solution:
import jwt
data = 'your_data'
key = 'your_secret_key'
encoded_data = jwt.encode(data, key, algorithm="HS256")
decoded_data = jwt.decode(encoded_data, key, algorithms=["HS256"])
More information is available in JWT Docs
I faced the same error when i was working with speech-to-text using ibm_watson then i solved my issue by installing PyJWT of version 1.7.1 to do that try:
pip install PyJWT==1.7.1
OR
python -m pip install PyJWT
Good Luck
For those who want to use the latest version(as of writing this v2.1.0) of PyJWT.
If you don't want to continue with the older version(i.e PyJWT==1.7.1) and want to upgrade it for some reason, you need to use the verify_signature parameter and set it to False(It is True by default if you don't provide it). In older versions (before <2.0.0) the parameter was verify and you could directly use that. but in the newer version, you have to use it inside options parameter which is of type dict
jwt.decode(...., options={"verify_signature": False})
If you don't want to use verify_signature, you can simply pass the algorithms parameter without verify_signature.
jwt.decode(.... algorithms=['HS256'])
This is from the official Changelog.
Dropped deprecated verify param in jwt.decode(...)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Use jwt.decode(encoded, key, options={"verify_signature": False})
instead.
Require explicit algorithms in jwt.decode(...) by default
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Example: jwt.decode(encoded, key, algorithms=["HS256"]).
I had this problem, with version 2.3.0 of jwt.
I have solved it like this:
jwt.decode(token, MY_SECRET, algorithms=['HS256'])
you must use algorithms instead of algorithm

Docker CLI allows tag, but Docker Python API raises APIError

I am trying to push a local Docker image to ECR using the Docker Python API. As part of that process I need to tag the image a certain way. When I do so on the CLI, it works:
docker tag foo/bar '{user_id}.dkr.ecr.us-east-1.amazonaws.com/foo/bar'
However when I try to do the same thing using the docker.images.Image.tag function in the Docker Python SDK it fails:
import docker
(docker.client.from_env().images.get('foo/bar')
.tag('foo/bar',
'{user-id}.dkr.ecr.us-east-1.amazonaws.com/foo/bar'
)
)
(replace user_id in the code samples above with an AWS user id value, e.g. 717171717171; I've obfuscated it here for the purposes of this question)
With the following error:
In [10]: docker.client.from_env().images.get('foo/bar').ta
...: g('foo/bar', '{user_id}.dkr.ecr.us-east-1.amaz
...: onaws.com/foo/bar')
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/docker/api/client.py in _raise_for_status(self, response)
255 try:
--> 256 response.raise_for_status()
257 except requests.exceptions.HTTPError as e:
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
939 if http_error_msg:
--> 940 raise HTTPError(http_error_msg, response=self)
941
HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.35/images/sha256:afe07035bce72b6c496878a7e3960bedffd46c1bedc79f1bd2b89619e8457194/tag?tag={user_id}.dkr.ecr.us-east-1.amazonaws.com%2Ffoo%2Fbar&repo=foo%2Fbar&force=0
During handling of the above exception, another exception occurred:
APIError Traceback (most recent call last)
<ipython-input-10-5bb015d17409> in <module>
----> 1 docker.client.from_env().images.get('alekseylearn-example/build').tag('foo/bar', '{user_id}.dkr.ecr.us-east-1.amazonaws.com/foo/bar')
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/docker/models/images.py in tag(self, repository, tag, **kwargs)
120 (bool): ``True`` if successful
121 """
--> 122 return self.client.api.tag(self.id, repository, tag=tag, **kwargs)
123
124
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/docker/utils/decorators.py in wrapped(self, resource_id, *args, **kwargs)
17 'Resource ID was not provided'
18 )
---> 19 return f(self, resource_id, *args, **kwargs)
20 return wrapped
21 return decorator
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/docker/api/image.py in tag(self, image, repository, tag, force)
531 url = self._url("/images/{0}/tag", image)
532 res = self._post(url, params=params)
--> 533 self._raise_for_status(res)
534 return res.status_code == 201
535
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/docker/api/client.py in _raise_for_status(self, response)
256 response.raise_for_status()
257 except requests.exceptions.HTTPError as e:
--> 258 raise create_api_error_from_http_exception(e)
259
260 def _result(self, response, json=False, binary=False):
~/miniconda3/envs/alekseylearn-dev/lib/python3.6/site-packages/docker/errors.py in create_api_error_from_http_exception(e)
29 else:
30 cls = NotFound
---> 31 raise cls(e, response=response, explanation=explanation)
32
33
APIError: 500 Server Error: Internal Server Error ("invalid tag format")
Why does the CLI command succeed and the Python API command fail?
In detailed Docker API lingo, an image name like 123456789012.dkr.ecr.us-east-1.amazon.aws.com/foo/bar:baz is split up into a repository (before the colon) and a tag (after the colon). The host-name part of the repository name is a registry. The default tag value if none is specified is the literal latest.
In your case, you already have an Image object, so you need to apply the two "halves" of the second argument:
docker.client.from_env().images.get('foo/bar')
.tag('{user-id}.dkr.ecr.us-east-1.amazonaws.com/foo/bar',
'latest'
)
(In many practical cases using the latest tag isn't a great idea; something like a timestamp or source control commit ID better identifies the image and helps indicate to services like ECS or EKS or plain Kubernetes that they need to do an update. Also, while the ECR image IDs are kind of impractically long, in a scripting context nothing stops you from using them directly; you can, for example, docker build -t 12345...amazonaws.com/foo/bar:abcdef0 and skip the intermediate docker tag step if you want.)

Categories

Resources