Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect error #230

Open
zhongguojunhun1 opened this issue Feb 28, 2024 · 10 comments
Open

Connect error #230

zhongguojunhun1 opened this issue Feb 28, 2024 · 10 comments

Comments

@zhongguojunhun1
Copy link

First of all, thank you for giving me the permission to experience TimeGPT. I installed nixtlats version 0.19.0 and successfully generated the key, but when I used timegpt.validate_token() to verify the key, ConnectError was displayed. What can I do?
problem

@MMenchero
Copy link
Contributor

Hi @zhongguojunhun1 please keep in mind that your token is private, so be mindful of that when sharing screenshoots that show part of it. I recommend using an environment variable for your token. You can learn how to use one here.

Now, regarding your issue, can you share what the error is? Since the image is cropped, I can't see what it says at the end. Additionally, please make sure you have TimeGPT credits or a valid payment method. The validate_token method makes an API call, so you need to have credits to do so. You can check this in your dashboard.

@zhongguojunhun1
Copy link
Author

zhongguojunhun1 commented Mar 6, 2024 via email

@MMenchero
Copy link
Contributor

sorry, what zip package? Here I can see that you sent something at 7:36 AM, but I'm not sure to where or whom.

@zhongguojunhun1
Copy link
Author

zhongguojunhun1 commented Mar 7, 2024

sorry, what zip package? Here I can see that you sent something at 7:36 AM, but I'm not sure to where or whom.

Hi,I re-uploaded the screenshot of the connect error problem, please help me analyze it.
1

2
3
4
5
6
7
8
9
10

@MMenchero
Copy link
Contributor

Hi @zhongguojunhun1, thanks for sharing the screenshots here on GitHub. I see now that you're trying to make an API request. Is there a specific reason you're not using nixtlats? The idea behind nixtlats is to avoid making direct API requests. Instead, you can simply instantiate the TimeGPT class and then call the forecast method.

@zhongguojunhun1
Copy link
Author

Hi @zhongguojunhun1, thanks for sharing the screenshots here on GitHub. I see now that you're trying to make an API request. Is there a specific reason you're not using nixtlats? The idea behind nixtlats is to avoid making direct API requests. Instead, you can simply instantiate the TimeGPT class and then call the forecast method.

Hi, dear developer!
I instantiated a TimeGPT class as you suggested and called the forecast method, but I still encountered connect error. The program error message is as follows:

INFO:nixtlats.timegpt:Validating inputs...
INFO:nixtlats.timegpt:Preprocessing dataframes...
INFO:numexpr.utils:NumExpr defaulting to 4 threads.
INFO:nixtlats.timegpt:Inferred freq: H
INFO:nixtlats.timegpt:Attempt 1 failed...
INFO:nixtlats.timegpt:Attempt 2 failed...
INFO:nixtlats.timegpt:Attempt 3 failed...
INFO:nixtlats.timegpt:Attempt 4 failed...
INFO:nixtlats.timegpt:Attempt 5 failed...
INFO:nixtlats.timegpt:Attempt 6 failed...

ConnectError Traceback (most recent call last)
D:\anaconda3\lib\site-packages\httpx_transports\default.py in map_httpcore_exceptions()
68 try:
---> 69 yield
70 except Exception as exc:

D:\anaconda3\lib\site-packages\httpx_transports\default.py in handle_request(self, request)
232 with map_httpcore_exceptions():
--> 233 resp = self._pool.handle_request(req)
234

D:\anaconda3\lib\site-packages\httpcore_sync\connection_pool.py in handle_request(self, request)
215 self._close_connections(closing)
--> 216 raise exc from None
217

D:\anaconda3\lib\site-packages\httpcore_sync\connection_pool.py in handle_request(self, request)
195 # Send the request on the assigned connection.
--> 196 response = connection.handle_request(
197 pool_request.request

D:\anaconda3\lib\site-packages\httpcore_sync\http_proxy.py in handle_request(self, request)
288 )
--> 289 connect_response = self._connection.handle_request(
290 connect_request

D:\anaconda3\lib\site-packages\httpcore_sync\connection.py in handle_request(self, request)
98 self._connect_failed = True
---> 99 raise exc
100

D:\anaconda3\lib\site-packages\httpcore_sync\connection.py in handle_request(self, request)
75 if self._connection is None:
---> 76 stream = self._connect(request)
77

D:\anaconda3\lib\site-packages\httpcore_sync\connection.py in _connect(self, request)
153 with Trace("start_tls", logger, request, kwargs) as trace:
--> 154 stream = stream.start_tls(**kwargs)
155 trace.return_value = stream

D:\anaconda3\lib\site-packages\httpcore_backends\sync.py in start_tls(self, ssl_context, server_hostname, timeout)
167 self.close()
--> 168 raise exc
169 return SyncStream(sock)

D:\anaconda3\lib\contextlib.py in exit(self, type, value, traceback)
130 try:
--> 131 self.gen.throw(type, value, traceback)
132 except StopIteration as exc:

D:\anaconda3\lib\site-packages\httpcore_exceptions.py in map_exceptions(map)
13 if isinstance(exc, from_exc):
---> 14 raise to_exc(exc) from exc
15 raise # pragma: nocover

ConnectError: [Errno 0] Error

The above exception was the direct cause of the following exception:

ConnectError Traceback (most recent call last)
in
----> 1 fcst_df = timegpt.forecast(df, h=24, level=[80, 90])

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in forecast(self, df, h, freq, id_col, time_col, target_col, X_df, level, finetune_steps, finetune_loss, clean_ex_first, validate_token, add_history, date_features, date_features_to_one_hot, model, num_partitions)
1086 """
1087 if isinstance(df, pd.DataFrame):
-> 1088 return self._forecast(
1089 df=df,
1090 h=h,

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in wrapper(self, *args, **kwargs)
626 f'supported models: {", ".join(self.supported_models)}'
627 )
--> 628 return func(self, *args, **kwargs)
629
630 return wrapper

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in wrapper(self, num_partitions, **kwargs)
644 def wrapper(self, num_partitions, **kwargs):
645 if num_partitions is None or num_partitions == 1:
--> 646 return func(self, **kwargs, num_partitions=1)
647 df = kwargs.pop("df")
648 X_df = kwargs.pop("X_df", None)

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in _forecast(self, df, h, freq, id_col, time_col, target_col, X_df, level, finetune_steps, finetune_loss, clean_ex_first, validate_token, add_history, date_features, date_features_to_one_hot, model, num_partitions)
782 max_wait_time=self.max_wait_time,
783 )
--> 784 fcst_df = timegpt_model.forecast(df=df, X_df=X_df, add_history=add_history)
785 self.weights_x = timegpt_model.weights_x
786 return fcst_df

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in forecast(self, df, X_df, add_history)
445 main_logger.info("Preprocessing dataframes...")
446 Y_df, X_df = self.preprocess_dataframes(df=df, X_df=X_df)
--> 447 self.set_model_params()
448 if self.h > self.model_horizon:
449 main_logger.warning(

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in set_model_params(self)
417
418 def set_model_params(self):
--> 419 model_params = self._call_api(
420 self.client.timegpt_model_params,
421 {"request": SingleSeriesForecast(freq=self.freq, model=self.model)},

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\timegpt.py in _call_api(self, method, kwargs)
161
162 def _call_api(self, method, kwargs):
--> 163 response = self._retry_strategy()(method)(**kwargs)
164 if "data" in response:
165 response = response["data"]

D:\anaconda3\lib\site-packages\tenacity_init_.py in wrapped_f(*args, **kw)
287 @functools.wraps(f)
288 def wrapped_f(*args: t.Any, **kw: t.Any) -> t.Any:
--> 289 return self(f, *args, **kw)
290
291 def retry_with(*args: t.Any, **kwargs: t.Any) -> WrappedFn:

D:\anaconda3\lib\site-packages\tenacity_init_.py in call(self, fn, *args, **kwargs)
377 retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs)
378 while True:
--> 379 do = self.iter(retry_state=retry_state)
380 if isinstance(do, DoAttempt):
381 try:

D:\anaconda3\lib\site-packages\tenacity_init_.py in iter(self, retry_state)
323 retry_exc = self.retry_error_cls(fut)
324 if self.reraise:
--> 325 raise retry_exc.reraise()
326 raise retry_exc from fut.exception()
327

D:\anaconda3\lib\site-packages\tenacity_init_.py in reraise(self)
156 def reraise(self) -> t.NoReturn:
157 if self.last_attempt.failed:
--> 158 raise self.last_attempt.result()
159 raise self
160

D:\anaconda3\lib\concurrent\futures_base.py in result(self, timeout)
430 raise CancelledError()
431 elif self._state == FINISHED:
--> 432 return self.__get_result()
433
434 self._condition.wait(timeout)

D:\anaconda3\lib\concurrent\futures_base.py in __get_result(self)
386 def __get_result(self):
387 if self._exception:
--> 388 raise self._exception
389 else:
390 return self._result

D:\anaconda3\lib\site-packages\tenacity_init_.py in call(self, fn, *args, **kwargs)
380 if isinstance(do, DoAttempt):
381 try:
--> 382 result = fn(*args, **kwargs)
383 except BaseException: # noqa: B902
384 retry_state.set_exception(sys.exc_info()) # type: ignore[arg-type]

D:\anaconda3\lib\site-packages\nixtlats-0.1.20-py3.8.egg\nixtlats\client.py in timegpt_model_params(self, request)
406 - request: SingleSeriesForecast.
407 """
--> 408 _response = self._client_wrapper.httpx_client.request(
409 "POST",
410 urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "timegpt_model_params"),

D:\anaconda3\lib\site-packages\httpx_client.py in request(self, method, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions)
825 extensions=extensions,
826 )
--> 827 return self.send(request, auth=auth, follow_redirects=follow_redirects)
828
829 @contextmanager

D:\anaconda3\lib\site-packages\httpx_client.py in send(self, request, stream, auth, follow_redirects)
912 auth = self._build_request_auth(request, auth)
913
--> 914 response = self._send_handling_auth(
915 request,
916 auth=auth,

D:\anaconda3\lib\site-packages\httpx_client.py in _send_handling_auth(self, request, auth, follow_redirects, history)
940
941 while True:
--> 942 response = self._send_handling_redirects(
943 request,
944 follow_redirects=follow_redirects,

D:\anaconda3\lib\site-packages\httpx_client.py in _send_handling_redirects(self, request, follow_redirects, history)
977 hook(request)
978
--> 979 response = self._send_single_request(request)
980 try:
981 for hook in self._event_hooks["response"]:

D:\anaconda3\lib\site-packages\httpx_client.py in _send_single_request(self, request)
1013
1014 with request_context(request=request):
-> 1015 response = transport.handle_request(request)
1016
1017 assert isinstance(response.stream, SyncByteStream)

D:\anaconda3\lib\site-packages\httpx_transports\default.py in handle_request(self, request)
231 )
232 with map_httpcore_exceptions():
--> 233 resp = self._pool.handle_request(req)
234
235 assert isinstance(resp.stream, typing.Iterable)

D:\anaconda3\lib\contextlib.py in exit(self, type, value, traceback)
129 value = type()
130 try:
--> 131 self.gen.throw(type, value, traceback)
132 except StopIteration as exc:
133 # Suppress StopIteration unless it's the same exception that

D:\anaconda3\lib\site-packages\httpx_transports\default.py in map_httpcore_exceptions()
84
85 message = str(exc)
---> 86 raise mapped_exc(message) from exc
87
88

ConnectError: [Errno 0] Error
1

@MMenchero
Copy link
Contributor

Ok, now that you're using nixtlats it should be easier to make it work. It looks to me that the error is in how the token is being loaded, so just this time load it directly to the TimeGPT class. Here's how:

from nixtlats import TimeGPT 
import os 
import pandas as pd 

timegpt = TimeGPT(token = 'your token')

df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short.csv')
fcst_df = timegpt.forecast(df, h=24, level=[80,90]) 
fcst_df.head()

This should work since you have enough credits in your dashboard. If that works, then please follow this guide to see how to properly secure your token.

You can also use the validate_token method from the TimeGPT class. Simply call timegpt.validate_token() after you instantiate the TimeGPT class. This should return True given that you have credits in your dashboard and assuming the token was copied correctly from there.

@zhongguojunhun1
Copy link
Author

Ok, now that you're using nixtlats it should be easier to make it work. It looks to me that the error is in how the token is being loaded, so just this time load it directly to the TimeGPT class. Here's how:

from nixtlats import TimeGPT 
import os 
import pandas as pd 

timegpt = TimeGPT(token = 'your token')

df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short.csv')
fcst_df = timegpt.forecast(df, h=24, level=[80,90]) 
fcst_df.head()

This should work since you have enough credits in your dashboard. If that works, then please follow this guide to see how to properly secure your token.

You can also use the validate_token method from the TimeGPT class. Simply call timegpt.validate_token() after you instantiate the TimeGPT class. This should return True given that you have credits in your dashboard and assuming the token was copied correctly from there.

Hi, dear developer!
I re-initialized the TimeGPT class using the method you provided, but calling the forecast method still encountered connect error. But I can draw the graph by calling the plot method. The operating system I use is windows 10, I would like to know whether it is related to the operating system, or the reason for the poor network.
error

@elephaint
Copy link
Contributor

@zhongguojunhun1 Do you still experience issues?

@RSM-AAN
Copy link

RSM-AAN commented Jun 10, 2024

having the same issue. Any suggestsion? Did you resolved it @zhongguojunhun1 ?

! pip install nixtla

from dotenv import load_dotenv
load_dotenv('../../.env')
NIXTLA_API_KEY = os.getenv('NIXTLA_API_KEY')

from nixtla import NixtlaClient

Check if the NIXTLA_API_KEY was successfully loaded

if NIXTLA_API_KEY is not None:
from nixtla import NixtlaClient
nixtla_client = NixtlaClient(api_key=NIXTLA_API_KEY)
print("Nixtla client successfully initialized.")
else:
print("Failed to load NIXTLA_API_KEY from the environment variables.")
Nixtla client successfully initialized.

nixtla_client.validate_api_key()
False

timegpt_fcst_df = nixtla_client.forecast(df=df, h=12, freq='MS', time_col='timestamp', target_col='value')

INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Attempt 1 failed...
INFO:nixtla.nixtla_client:Attempt 2 failed...
INFO:nixtla.nixtla_client:Attempt 3 failed...
INFO:nixtla.nixtla_client:Attempt 4 failed...
INFO:nixtla.nixtla_client:Attempt 5 failed...
INFO:nixtla.nixtla_client:Attempt 6 failed...

ConnectError Traceback (most recent call last)
File c:\Users\Anna.Androvitsanea\AppData\Local\Programs\Python\Python310\lib\site-packages\httpx_transports\default.py:69, in map_httpcore_exceptions()
68 try:
---> 69 yield
70 except Exception as exc:

File c:\Users\Anna.Androvitsanea\AppData\Local\Programs\Python\Python310\lib\site-packages\httpx_transports\default.py:233, in HTTPTransport.handle_request(self, request)
232 with map_httpcore_exceptions():
--> 233 resp = self._pool.handle_request(req)
235 assert isinstance(resp.stream, typing.Iterable)

File c:\Users\Anna.Androvitsanea\AppData\Local\Programs\Python\Python310\lib\site-packages\httpcore_sync\connection_pool.py:216, in ConnectionPool.handle_request(self, request)
215 self._close_connections(closing)
--> 216 raise exc from None
218 # Return the response. Note that in this case we still have to manage
219 # the point at which the response is closed.

File c:\Users\Anna.Androvitsanea\AppData\Local\Programs\Python\Python310\lib\site-packages\httpcore_sync\connection_pool.py:196, in ConnectionPool.handle_request(self, request)
194 try:
195 # Send the request on the assigned connection.
--> 196 response = connection.handle_request(
197 pool_request.request
198 )
199 except ConnectionNotAvailable:
...
83 raise
85 message = str(exc)
---> 86 raise mapped_exc(message) from exc

ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants