Im trying to invoke a function in a mlrun but getting above error. can anyone please help me with that.im attaching code here...
from cloudpickle import load
import numpy as np
from typing import List
import mlrun
class ClassifierModel(mlrun.serving.V2ModelServer):
def load(self):
"""load and initialize the model and/or other elements"""
model_file, extra_data = self.get_model('.pkl')
self.model = load(open(model_file, 'rb'))
def predict(self, body: dict) -> List:
"""Generate model predictions from sample."""
feats = np.asarray(body['inputs'])
result: np.ndarray = self.model.predict(feats)
return result.tolist()
#The following code converts the ClassifierModel class that you defined in the previous step to a serving function. The name of the class to be used by the serving function is set in spec.default_class.
serving_fn = mlrun.code_to_function('serving', kind='serving',image='mlrun/mlrun')
serving_fn.spec.default_class = 'ClassifierModel'
model_file = project.get_artifact_uri('my_model')
serving_fn.add_model('my_model',model_path=model_file)
#Testing Your Function Locally
my_data = '''{"inputs":[[5.1, 3.5, 1.4, 0.2],[7.7, 3.8, 6.7, 2.2]]}'''
server = serving_fn.to_mock_server()
server.test("/v2/models/my_model/infer", body=my_data)
# Building and Deploying the Serving Function¶
function_address = serving_fn.deploy()
print (f'The address for the function is {function_address} \n')
!curl $function_address
# Now we will try to invoke our serving function
serving_fn.invoke('/v2/models/my_model/infer', my_data)
OSError: error: cannot get build status, HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /api/v1/build/status?name=serving&project=getting-started-jovyan&tag=&logs=yes&offset=0&last_log_timestamp=1664873747518.8518&verbose=no (Caused by ReadTimeoutError("HTTPConnectionPool(host='localhost', port=8080): Read timed out. (read timeout=45)"))
By the looks of it, there's nothing listening on localhost:8080, even though there should be.
According to the getting started guide there should be an "MLRun Backend Service", presumably on that address by default. I suspect you haven't started the service.
The address localhost:8080 in not accessible from docker-composer, it means you have to do MLRun installation to the different IP address. I see two steps, how to solve the issue:
Relevant installation
The MLRun Community Edition in desktop docker has to be install under relevant HOST_IP (not with localhost or 127.0.0.1, but with stable IP address, see ipconfig) and with relevant SHARED_DIR. See relevant command line (from OS windows):
set HOST_IP=192.168.0.150
set SHARED_DIR=c:\Apps\mlrun-data
set TAG=1.2.0
mkdir %SHARED_DIR%
docker-compose -f "c:\Apps\mlrun\compose.with-jupyter.yaml" up
BTW: YAML file see https://docs.mlrun.org/en/latest/install/local-docker.html
2. Access to the port
In case of call serving_fn.invoke you have to open relevant port (from deploy_function) on your IP address (based on setting of HOST_IP, see the first point).
Typically this port can be blocked based on your firewall policy or your local antivirus. It means, you have to open access to this port before invoke call.
BTW:
You can test access to the port via telnet also
You can see focus on the issue https://github.com/mlrun/mlrun/issues/2102
Related
I'm trying to access Azure EvenHub but my network makes me use proxy and allows connection only over https (port 443)
Based on https://learn.microsoft.com/en-us/python/api/azure-eventhub/azure.eventhub.aio.eventhubproducerclient?view=azure-python
I added proxy configuration and TransportType.AmqpOverWebsocket parametr and my Producer looks like this:
async def run():
producer = EventHubProducerClient.from_connection_string(
"Endpoint=sb://my_eh.servicebus.windows.net/;SharedAccessKeyName=eh-sender;SharedAccessKey=MFGf5MX6Mdummykey=",
eventhub_name="my_eh",
auth_timeout=180,
http_proxy=HTTP_PROXY,
transport_type=TransportType.AmqpOverWebsocket,
)
and I get an error:
File "/usr/local/lib64/python3.9/site-packages/uamqp/authentication/cbs_auth_async.py", line 74, in create_authenticator_async
raise errors.AMQPConnectionError(
uamqp.errors.AMQPConnectionError: Unable to open authentication session on connection b'EHProducer-a1cc5f12-96a1-4c29-ae54-70aafacd3097'.
Please confirm target hostname exists: b'my_eh.servicebus.windows.net'
I don't know what might be the issue.
Might it be related to this one ? https://github.com/Azure/azure-event-hubs-c/issues/50#issuecomment-501437753
you should be able to set up a proxy that the SDK uses to access EventHub. Here is a sample that shows you how to set the HTTP_PROXY dictionary with the proxy information. Behind the scenes when proxy is passed in, it automatically goes over websockets.
As #BrunoLucasAzure suggested checking the ports on the proxy itself will be good to check, because based on the error message it looks like it made it past the proxy and cant resolve the endpoint.
I deployed Minio on Kubernetes by using the new operator:
helm repo add minio https://operator.min.io/
helm install --namespace minio-operator --create-namespace --generate-name minio/minio-operator
kubectl apply -f https://raw.githubusercontent.com/minio/operator/master/examples/tenant-tiny.yaml
sudo -E kubefwd svc
Port-Forward: 127.1.27.1 minio:80 to pod minio-ss-0-0:9000
Port-Forward: 127.1.27.2 minio-hl:9000 to pod minio-ss-0-0:9000
Port-Forward: 127.1.27.3 minio-ss-0-0.minio-hl:9000 to pod minio-ss-0-0:9000
The Tenant is working and I can access the web console both at minio:80 and minio-hl:9000
I'd like to access the storage from outside the cluster (Jupyter notebook running on Docker); this is where I receive the error "ConnectionRefusedError: [Errno 111] Connection refused":
def main():
client = Minio(
"minio:80", #minio-hl:9000 leads to the same error
access_key="minio",
secret_key="minio123!",
secure=False
)
found = client.bucket_exists("posts")
if not found:
client.make_bucket("posts")
print("Bucket 'posts' created")
else:
print("Bucket 'posts' already exists")
I also tried using pyspark with s3a jars for writing-reading objects but the connection hangs for a long time, finally receiving a similar error.
Can someone help me please? Thanks a lot!
Hope it's not too late to provide the info below:
First of all, make sure you can get access to the service after port-forward. Then try to use minio python client to do similar thing.
Actually, I have got similar issue with yours recently and finally solved by using custom http client after double confirming the service is accessible after port-forward.
from minio import Minio
from minio.error import InvalidResponseError
import urllib3
def main():
httpClient = urllib3.PoolManager(
cert_reqs="CERT_NONE")
client = Minio('my-domain:443',
access_key='xxxxx',
secret_key='xxxxx',
http_client=httpClient
)
try:
objects = client.list_objects('bucket_name', prefix='/', recursive=True)
for obj in objects:
print(obj.bucket_name)
except InvalidResponseError as err:
print("error", err)
I'm calling a function from my terminal, which connects to the Google Maps API to return the coordinates of a place.
However, I'm getting this error
sock.connect((self.host, self.port))
TimeoutError: [Errno 60] Operation timed out
The process is as follows:
>>>> python
>>>> from geocode import getGeocodeLocation
>>>> getGeocodeLocation("New York")
Error:
sock.connect((self.host, self.port))
TimeoutError: [Errno 60] Operation timed out
The code I'm using is as follows geocode.py - I don't think there a problem with this as it ran fine before.
import httplib2
import json
def getGeocodeLocation(inputString):
# Use Google Maps to convert a location into Latitute/Longitute coordinates
google_api_key = "my_api_key"
locationString = inputString.replace(" ", "+")
url = ('https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s'% (locationString, google_api_key))
h = httplib2.Http()
result = json.loads(h.request(url,'GET')[1])
latitude = result['results'][0]['geometry']['location']['lat']
longitude = result['results'][0]['geometry']['location']['lng']
return (latitude,longitude)
Any ideas what might be wrong?
I get (40.7127753, -74.0059728) as output when I run your exact code (with my own key) on RStudio Cloud. So this is likely an API key-related, environment-related or network-related issue.
To narrow down the issue I recommend you try it out on the same platform. These is how I set it up:
geocode.py
import httplib2
import json
def getGeocodeLocation(inputString):
# Use Google Maps to convert a location into Latitute/Longitute coordinates
google_api_key = "MY_API_KEY"
locationString = inputString.replace(" ", "+")
url = ('https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s'% (locationString, google_api_key))
h = httplib2.Http()
result = json.loads(h.request(url,'GET')[1])
latitude = result['results'][0]['geometry']['location']['lat']
longitude = result['results'][0]['geometry']['location']['lng']
return (latitude,longitude)
main.py
from geocode import getGeocodeLocation
getGeocodeLocation("New York")
Also make sure that your API key is valid and that you have billing and Geocoding API enabled on your project. Refer to Google's get started guide.
Hope this helps you!
the issue with your local internet environment with your code editor, if you paste the request URL with the API key, the response is normal. but in the local, request from your local code. it will not work, I solved it with the wire guard mode of my VPN, a similar situation is discussed here as well I have just discovered that my new ISP is blocking outbound connection on port 445.
I want to connect to a Wi-Fi network using Python on OS X (10.11). Based on CWInterface reference I figured out there is a iface.associateToNetwork_password_error_() method available, however when called it does not connect to the network nor it does cause any exception.
At the same time iface.disassociate() works correctly and disconnects WiFi.
This is the code I tried:
import objc
objc.loadBundle('CoreWLAN',
bundle_path='/System/Library/Frameworks/CoreWLAN.framework',
module_globals=globals())
iface = CWInterface.interface()
iface.associateToNetwork_password_error_(SSID, PASSWORD, None)
How can I connect to a specified network from Python on OS X and make sure the connection has been established?
I was able to successfully connect to my home network with the following:
import objc
objc.loadBundle('CoreWLAN',
bundle_path = '/System/Library/Frameworks/CoreWLAN.framework',
module_globals = globals())
iface = CWInterface.interface()
networks, error = iface.scanForNetworksWithName_error_('<Name Of Network>', None)
network = networks.anyObject()
success, error = iface.associateToNetwork_password_error_(network, '<Password Of Network>', None)
Two key things that I suspect you were missing:
You weren't passing in a CWNetwork as your first parameter.
You weren't checking return values (IE, success and error in the final call). They could have helped you with tracking down any other issues, perhaps.
I've created some web services using pysimplesoap like on this documentation:
https://code.google.com/p/pysimplesoap/wiki/SoapServer
When I tested it, I called it like this:
from SOAPpy import SOAPProxy
from SOAPpy import Types
namespace = "http://localhost:8008"
url = "http://localhost:8008"
proxy = SOAPProxy(url, namespace)
response = proxy.dummy(times=5, name="test")
print response
And it worked for all of my web services, but when I try to call it by using an library which is needed to specify the WSDL, it returns "Could not connect to host".
To solve my problem, I used the object ".wsdl()" to generate the correct WSDL and saved it into a file, the WSDL generated by default wasn't correct, was missing variable types and the correct server address...
The server name localhost is only meaningful on your computer. Once outside, other computers won't be able to see it.
1) find out your external IP, with http://www.whatismyip.com/ or another service. Note that IPs change over time.
2) plug the IP in to http://www.soapclient.com/soaptest.html
If your local service is answering IP requests as well as from localhost, you're done!