Query Crate Database by SQLAlchemy Dialect: No more Servers available - python-3.x

I'd like to give it a try with crate. I first tried it by loading some twitter data and query from admin UI successfully. However, when I tried to make a query with SQLAlchemy, I've got the following error.
OperationalError: (crate.client.exceptions.ConnectionError)
No more Servers available, exception from last server: HTTPConnectionPool(host='localhost', port=4200):
Max retries exceeded with url:
/_sql (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f51485b2c18>:
Failed to establish a new connection: [Errno 111] Connection refused'))
[SQL: SELECT * FROM tweets LIMIT 100; ]
(Background on this error at: http://sqlalche.me/e/e3q8)
This is the code I ran that caused the error.
from crate import client
import sqlalchemy as sa
import pandas as pd
engine = sa.create_engine('crate://localhost:4200')
query = (
"SELECT * "
"FROM tweets "
"LIMIT 100; "
)
df = pd.read_sql(query, engine)
Any idea how to fix it (the settings are all default)?
Update:
Crate is running on host system while Jupyter is running in a container on the same machine.
I can access Crate via "http://localhost:4200" on the host machine but can't do "http://xxx.xxx.xxx.xxx:4200" from other machine in the same natwork.
I tried both:
engine = sa.create_engine('crate://10.7.116.222:4200')
engine = sa.create_engine('crate://')
which caused the same error:
Removed server http://127.0.0.1:4200 from active pool
Removed server http://127.0.0.1:4200 from active pool
OperationalError: (crate.client.exceptions.ConnectionError)
No more Servers available, exception from last server:
HTTPConnectionPool(host='127.0.0.1', port=4200):
Max retries exceeded with url:
/_sql (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5147faaa58>:
Failed to establish a new connection: [Errno 111] Connection refused'))
[SQL: SELECT * FROM tweets LIMIT 10; ]
(Background on this error at: http://sqlalche.me/e/e3q8)

I haven't tried it but according to the documentation 'localhost:4200' is assumed so you could connect using just engine = sa.create_engine('crate://')

Related

Https Connection failure via Proxy Server in Python

I am trying to read and send emails (O365) using OAuth2. This code works fine on my local machine, but
when I am trying to deploy this in a server where there is a proxy to access the internet, I am getting the below error.
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /2d11ad74-bbf6-403f-32c7-6ff0e039a923/oauth2/v2.0/token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002507067C348>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))
Below is my code I tried:
import settings
from exchangelib import Credentials, Account, DELEGATE, BASIC, \
Configuration, NTLM, Message, Mailbox, FileAttachment, HTMLBody, FaultTolerance, IMPERSONATION
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter
from exchangelib import OAuth2LegacyCredentials
credentials = OAuth2LegacyCredentials(
client_id= settings.clientId, client_secret= settings.clientSecret,
tenant_id=settings.tenentId,
username=settings.eUserName, password=settings.ePassword
)
config = Configuration(server = 'smtp.office365.com', credentials=credentials)
account = Account(settings.eUserName, config=config, access_type=DELEGATE)
m = Message(
account=account,
subject='Any Subject OAth2 Authentication',
body=HTMLBody('OAth2 Authentication'),
to_recipients=map(lambda x: Mailbox(email_address=x), ['myEmail#gmail.com'])
)
for item in account.inbox.all()[:10]:
print (item.sender.email_address)
m.send()
print('Email is being sent...')
You probably need to add setup proxy configuration. Here's how to do that in exchangelib:
https://ecederstrand.github.io/exchangelib/#proxies-and-custom-tls-validation

python3 request POST times out when calling Azure function app

I have a python program that reads a file and posts the data to an Azure function app. Over the past few weeks, I have started noticing this error in the logs. This program is about a year old and has never had an issue like this.
HTTPSConnectionPool(host=xxxx.azurewebsites.net', port=443): Max retries exceeded with url: /api/xxxx?code=zzzzzzzzzzz== (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff96b5f0790>: Failed to establish a new connection: [Errno 110] Connection timed out'))
offending line from program:
response = requests.request("POST", xxxx.azurewebsites.net, json=post_data)
I do not get the error every time.
What could/would cause this issue and how do I correct it?

Azure Custom Vision SDK - ClientRequestError

I am trying out an object detection project with the Custom Vision client library. But I get ClientRequestError. Below is my code:-
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateEntry
from msrest.authentication import ApiKeyCredentials
cv_endpoint = "https://westeurope.api.cognitive.microsoft.com"
training_key = "*******************"
training_images = "LegoSimpsons/TrainingImages"
credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(credentials=credentials,endpoint=cv_endpoint)
for domain in trainer.get_domains():
print(domain.id, "\t", domain.name)
I get the below error:
ClientRequestError: Error occurred in request., ProxyError:
HTTPSConnectionPool(host='southcentralus.api.cognitive.microsoft.com',
port=443): Max retries exceeded with url:
/customvision/v3.4-preview/training/domains (Caused by
ProxyError('Cannot connect to proxy.',
NewConnectionError('<urllib3.connection.HTTPSConnection object at
0x000001CA81115588>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it')))
Seems there is something wrong with your cv_endpoint, If you have created a Custom Vision Training service in your subscription:
you can find the key and endpoint here:
This is my test result:

Is any way to fix NewConnectionError occurred while calling a API?

I am trying to call an API which used to work fine previously, suddenly it started to throw newConnectionError. How can I get this fixed?
I tried to run the same API on my local machine and on the test environment, working fine there.
I expect a successful connection.
Error Message:
eport (Caused by NewConnectionError(': Failed to establ
ish a new connection: [Errno 110] Connection timed out',)).

Unable to connect h2o server python3

I have a problem trying to connect to the h2o server. The first time i'm able to do it. But the second time i get this error:
[18:56.78] H2OConnectionError: Unexpected HTTP error: HTTPConnectionPool(host='127.0.0.1', port=54321): Max retries exceeded with url: /3/Cloud (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f3041303dd8>: Failed to establish a new connection: [Errno 111] Connection refused',))
At the begining of my script i have:
h2o.init(ip="127.0.0.1", port="54321")
I down know if the first time the connection didnt close. Any body can help me?
Thank you very much

Resources