I have a timeout error in reading my data.
I'm in my company, so I have to write pip install --proxy=http://ep.threatpulse.net:80 pandas in order to install pandas.
Is it a prozy problem?
import pandas as pd
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
df = pd.read_csv(url, names=['sepal length','sepal width','petal length','petal width','target'])
and the result comes like this:
urlopen error [Errno 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
Yes this error comes because its not able to establish a connection to the internet- network error or proxy setting issue. You can check the proxy setting on you IE, if its taking by default or try on another PC in the same network or ask system admin in your company to allow the access.
You can try set the proxy something like this!
import io
import requests
proxy_dict = {"https":"https://xx.xx.x.xx:80"} #replace proxy setting here
response = requests.get(url, proxies=proxy_dict).text
df = pd.read_csv(io.StringIO(response),header=None)
df.columns = ['sepal length in cm','sepal width in cm',
'petal length in cm','petal width in cm','class']
Related
I am trying to establish a connection to DB2 which was working fine but after the change and update of SSL, it gave this error: com.ibm.db2.jcc.am.DisconnectNonTransientException: [jcc][t4][2034][11148][4.27.25] Execution failed due to a distribution protocol error that caused deallocation of the conversation. A DRDA Data Stream Syntax Error was detected. Reason: 0x3. ERRORCODE=-4499, SQLSTATE=-58009. Despite I had updated the cert and did the set up of the connection settings and connection was ok, the codes are giving this error. Can anyone help to advice where did I miss out or anything wrong with my script pls.
import os
from subprocess import Popen, PIPE, run
import jaydebeapi
from project_lib import Project
project = Project.access()
abc_connection = project.get.connection(name="abc")
abc_connection = jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver',
'{}://{}:{}/{}:user={};password={};'.format('jdbc:db2',
abc_credentials['host'],
abc_credentials['port'],
abc_credentials['database'], '/project_data/data_asset/ssl_cert.crt',
abc_credentials['username'],
abc_credentials['password']))
curs = abc_connection.cursor()
Any help is appreciated. Thanks.
In this code I call requests.post() in a loop and it gives me an error
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(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', None, 10060, None))
How can I fix this error? I searched for an answer for similar questions but they were not very similar to my problem and I did not understand
import pandas as pd
import numpy as np
import requests
URL = 'https://recruitment.aimtechnologies.co/ai-tasks'
df = pd.read_csv('dialect_dataset.csv', dtype=str)
batches = df.shape[0]//1000
size = 1000
data_id = []
data_tweets = []
for batch in range(batches+1):
#print("===========================")
ids = np.array(df['id'][size*batch:size*batch+size]).tolist()
data_id.extend(ids)
req = requests.post(URL, json= ids)
data_tweets.extend(req.json().values())
Referencing the following video: An OPC UA sample server in written in python using its opcua module
I am trying to implement this server on my own, so that I can later make modifications to it. I have PyDev for Eclipse installed as used in the video.
Here is the code used in the video:
from opcua import Server
from random import randint
import datetime
import time
server = Server()
url = "opc.tcp://192.168.0.8:4840"
server.set_endpoint(url)
name = "OPC_SIMULATION_SERVER"
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")
Temp = Param.add_variable(addspace, "Temperature", 0)
Press = Param.add_variable(addspace, "Pressure", 0)
Time = Param.add_variable(addspace, "Time", 0)
Temp.set_writable()
Press.set_writable()
Time.set_writable()
server.start()
print("Server started at {}".format(url))
while True:
Temperature = randint(10,50)
Pressure = randint(200, 999)
TIME = datetime.datetime.now()
print(Temperature, Pressure, TIME)
Temp.set_value(Temperature)
Press.set_value(Pressure)
Time.set_value(TIME)
time.sleep(2)
When I try to run this code, I get the following errors, which appear to be related to one another:
Error Image
If you could help me identify the source of errors, and possible resolutions to them I would appreciate it.
Edit: I was able to configure the server and it ran as expected. However, I now wish to connect it to a client to read in the data. When I try to do this, the connection is established but no data is read in. What are some potential fixes to this issue?
I have this simple minimal 'working' example below that opens a connection to google every two seconds. When I run this script when I have a working internet connection, I get the Success message, and when I then disconnect, I get the Fail message and when I reconnect again I get the Success again. So far, so good.
However, when I start the script when the internet is disconnected, I get the Fail messages, and when I connect later, I never get the Success message. I keep getting the error:
urlopen error [Errno -2] Name or service not known
What is going on?
import urllib2, time
while True:
try:
print('Trying')
response = urllib2.urlopen('http://www.google.com')
print('Success')
time.sleep(2)
except Exception, e:
print('Fail ' + str(e))
time.sleep(2)
This happens because the DNS name "www.google.com" cannot be resolved. If there is no internet connection the DNS server is probably not reachable to resolve this entry.
It seems I misread your question the first time. The behaviour you describe is, on Linux, a peculiarity of glibc. It only reads "/etc/resolv.conf" once, when loading. glibc can be forced to re-read "/etc/resolv.conf" via the res_init() function.
One solution would be to wrap the res_init() function and call it before calling getaddrinfo() (which is indirectly used by urllib2.urlopen().
You might try the following (still assuming you're using Linux):
import ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
res_init = libc.__res_init
# ...
res_init()
response = urllib2.urlopen('http://www.google.com')
This might of course be optimized by waiting until "/etc/resolv.conf" is modified before calling res_init().
Another solution would be to install e.g. nscd (name service cache daemon).
For me, it was a proxy problem.
Running the following before import urllib.request helped
import os
os.environ['http_proxy']=''
response = urllib.request.urlopen('http://www.google.com')
I'm posting this because I tried searching for the answer myself and I was not able to find a solution. I was eventually able to figure out a way to get this to work & I hope this helps someone else in the future.
Scenario:
In Windows XP, I'm using Python with Pandas & Quandl to get data for a US Equity security using the following line of code:
bars = Quandl.get("GOOG/NYSE_SPY", collapse="daily")
Unfortunately, I was getting the following error:
urllib2.URLError: <urlopen error [Errno 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>
#user3150079: kindly Ctrl+X / Ctrl+V your solution as an [Answer]. Such MOV is perfectly within StackOverflow
Solution:
I recognized that this was an issue with trying to contact a server without properly targeting my network's proxy server. Since I was not able to set the system variable for HTTP_PROXY, I added the following line which corrected the issue:
import os
os.environ['HTTP_PROXY']="10.11.123.456:8080"
Thanks - I'm interested to hear about any improvements to this solution or other suggestions.
You can set your user environment variable HTTP_PROXY if you can't or won't set the system environment variable:
set HTTP_PROXY "10.11.123.456:8080"
python yourscript.py
and to permanently set it (using setx from Windows XP Service Pack 2 Support Tools):
setx HTTP_PROXY "10.11.123.456:8080"
python yourscript.py
Other ways to get this environment variable set include: registry entries, putting os.environ["HTTP_PROXY"] = ..." insitecustomize.py`.
More control using requests without using the Quandl Package:
import requests
def main():
proxies = {'http': 'http://proxy.yourdomain.com:port',
'https': 'http://proxy.yourdomain.com:port',}
url = 'https://www.quandl.com/api/v3/datasets/GOOG/NYSE_SPY.json?collapse=daily'
response = requests.get(url, proxies=proxies)
status = response.status_code
html_text = response.text
repo_data = response.json()
print(repo_data)
print(status)
print('HTML TEXT')
print('=========')
print(html_text)
if __name__ == '__main__':
main()