Lets consider 'mywebsite' as my website uname as username and pwd as password.
Now the scenario is i have a system that was previously working but now when i am trying to connect to my magento from odoo it returns me an error
<ProtocolError for mywebsite/index.php/api/xmlrpc/: 301 Moved Permanently>
however this particular url ie https://mywebsite.com is accesible if you hit it on browser and also returns a true result when hit with Postman
i tried to hit the same url using a python script
import xmlrpclib
server = xmlrpclib.ServerProxy('https://mywebsite.com')
session = server.login('uname','pwd')
Multiple times over multiple environments
when i execute this script from the same environment that my server is hosted upon i get the same error
Error 301 Moved Permenantly
Now when i hit the same above script from my local enviroment i get
SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
which i assumed arises due to using https so when i change the url with http i get same error back which is
xmlrpclib.ProtocolError: <ProtocolError for mywebsite.com/: 301 Moved Permanently>
Hitting the above scripts from a staging environment gets me the same result as my local enviroment
also when i change the above script and run it using ip of the website along with port i get
socket.error: [Errno 110] Connection timed out
then i tried changing the script and running it with this code
import urllib
print urllib.urlopen("http://mywebsite.com/").getcode()
when i run this code from my local machine i get
Error 403 Forbidden Request
Hitting this new code with ip of website with port gets me
IOError: [Errno socket error] [Errno 110] Connection timed out
When i hit this code without mentioning the port i get
SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
now hitting these code from live environment using mywebsite.com gets me
Error 403
using ip without the port
[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)
with the ip and port
IOError: [Errno socket error] [Errno 110] Connection timed out
Any pointers or suggestions would be appreciated
if there are any silly mistakes please excuse them as i am a amateur in odoo/python
also if you have any other way to check if a url is hit-able please do let me know
Well it seems that when i entered the mywebsite url in odoo it was being appended in the backend by /index.php/api/xmlrpc which was working fine for some time
but now due to some changes it doesnt accept index.php anymore as it is automatically routed(mayb)
anyways i solved the error by changing the appending string to /api/xmlrpc
Related
I'm already using P4V client and everything is fine, no connection error.
Error:
I've got some SSL errors when I try to execute p4 command from Python.
And it's random, If i re run the script, error isnt thrown everytime
From the client, the output is :
SSL receive failed.\nread: Operation succeed : WSAECONNRESET
From the server side logs, i've got :
Connection from 90.XX.XX.93:53929 broken. SSL receive failed. read:
Connection reset by peer: Connection reset by peer
After le P4 Connection with p4.connect(), I run a p4.run_trust() command and the result seems ok
Trust already established
This error is trown doing a p4 fetch, of p4 edit myfile
Configuration
I'm starting my python script from the same computer running the P4V client. I'm using the same configuration ( user, workspace, url+port > ssl:p4.our-url.domain:1666 ). The SSL error happened with or without the P4V client started.
The SSL certificate was generated during the Perforce Server installation and configuration.
There is no apache server behind our subdomain p4.our-domain, so I can't test the SSL certificate using online SSL checker ( my network knowledge reach its limit there )
When i do a p4 info there is a "peer address", basically my IP with a random generated port (53929). What is this port ? Do i need to set a fixed port and redirect to my computer runing the script ?
Do you have any ideas where that error come from ? Is that a bad server configuration ( weird cause every p4v client in the office works).
Do i need to establish and distribute a new certificate to all users of the P4Python script ?
Python 3.5.4
PyOpenssl 18.0.0
P4Python 2017.2.1615960
Thanks a lot for any advice.
ANSWER suggested by Sam Stafford
Sam was right, It seems I got a timeout. I was opening the P4 connection and connecting to the server on the script launch, then processing was launched to generate files before using p4 fetch/add/submit. Here is a workaround to reconnect in case on disconnection from the server
# self.myp4 = P4() was created on init, files are added
submited = False
maxTry = 5
while not submited and maxTry > 0:
try:
reslist = self.p4.run_submit(ch)
except P4Exception as p4e:
print(str(self.p4.errors))
self.myp4.disconnect()
maxTry -= 1
self.myp4.connect()
submited = reslist is not None and len(reslist) > 0
That works if you want to keep the connection open. I guess the best way to avoid timeout is to call P4.connect() method just before any P4.run_*method*() and close it after. Instead of wating for timeout to restart the connection.
"Connection reset by peer" is a TCP error.
What does "connection reset by peer" mean?
Maybe your script is holding its connection open longer than P4V does, and a transient network failure during that period causes the connection to be reset? The best fix is probably to have the script catch the error, open a new connection, and pick up where it left off.
I am trying to do the following:
from urllib.request import urlopen
data = urlopen("https://www.duolingo.com/users/SaifullahS6").read()
I get the following error:
URLError: <urlopen error [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>
Similarly, when I try this:
import requests
session = requests.Session()
data = {"login": "SaifullahS6", "password": "mypassword"}
req = requests.Request('POST', "https://www.duolingo.com/login", data=data,
cookies=session.cookies)
prepped=req.prepare()
returned = session.send(prepped)
I get:
ConnectionError: HTTPSConnectionPool(host='www.duolingo.com', port=443): Max retries exceeded with url: /login (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000000000E6948D0>: 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',))
I am not sure how to give details of my internet connection.
I'm at work and I know we have a corporate proxy.
We have Windows Firewall turned on, but i have checked that python and pythonw are ticked in the "Domain" column of the control panel for allowing a program through the firewall.
When I ping google.co.uk from a command shell, all four requests time out, but I can access it from a browser.
In the Internet Options control panel, I click on the Connections tab and then LAN settings, and I have "Automatically detect settings" turned on, and also "Use a proxy server for your LAN", "Address" is "localhost" and "Port" is 3128. This is cntlm. I set it up once to do download python packages, and it appears to still be active because I have just managed to update one of my packages.
I don't even need a direct answer to my question; at this point I'll just settle for some clarity on what is actually going on behind the scenes. Any help much appreciated!
For the first case above (urllib module), I solved it by inserting the following lines before the data = urlopen(...).read() line:
proxies = { "http": "localhost:3128",
"https": "localhost:3128"}
proxy = urllib.request.ProxyHandler(proxies)
opener = urllib.request.build_opener(proxy)
urllib.request.install_opener(opener)
For the second case (requests module), everything was the same except the last line:
proxies = { "http": "localhost:3128",
"https": "localhost:3128"}
returned = session.send(prepped, proxies=proxies)
Hope this note helps others who come across this page.
I am testing out a script in python that saves some arbitrary values in a mongo database. This script runs on one Virtual Machine and the mongo db runs on another Virtual Machine. While testing localy (without deployidng my code to the VMs) everything worked perfectly but since I started testing on the VMs I get this error:
File "/usr/lib/python2.7/urllib2.py", line 1169, in do_open raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
I try to connect to the mongo VM by using this code snippet:
import os, pyjsonrpc
storeClient = pyjsonrpc.HttpClient(
url = os.getenv("URL_DATASTORE", "http://localhost:8081/jsonrpc/"),
username = "",
password = "")
I can ping my mongodb VM with no problem from my script VM but the moment I try to connect via the storeClient I get the urllib2 error. Any ideas?
You are trying to access the wrong server:
url = os.getenv("URL_DATASTORE", "http://localhost:8081/jsonrpc/"),
# ^^^^^^^^^
You are running it on a different VM, not localhost.
I am running a Nominatim web service by geopy, but it fails very often, due to usage policy or maybe Internet connection. How can I handle failing connection with a stop, and rerun the code after several seconds or minutes. The error message is:
GeocoderServiceError: <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>
and
GeocoderServiceError: HTTP Error 420: unused
The pseudo codes would be like:
try:
run web service
except:
stop several seconds or minutes and rerun webservice at the same line and loops
(if it fails again)
stop 30 minutes and rerun webservice
Any hint or suggestions will be the most welcome.
Thanks!
Thanks for the above comments. Revising try/ except is the solution.
Based on the geopy documentation (http://geopy.readthedocs.org/en/latest/#exceptions), the most common exception of using geopy is GeocoderServiceError. Here is the revising code to handle errors.
try:
run web service
except geopy.exc.GeocoderServiceError as e:
if e.message == 'HTTP Error 420: unused':
time.sleep(1800)
run web service
elif e.message == '<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>':
time.sleep(5)
run web service
I am attempting to open a connection via FTP using the following simple code. But the code is just hanging at this line. Its not advancing, its not throwing any exceptions or errors. My code is 6 months old and I've been able to use this code to connect to my website and download files all this time. Today its just started to hang when I go to open a FTP connection.
Do you know what could be going wrong?
ftp = ftplib.FTP("www.mySite.com") # hangs on this line
print("Im alive") # Never get printed out
ftp.login(username, password)
I administer the website with a couple of other people but we haven't changed anything.
Edit: Just tried to FTP in using Filezilla with the same username and password and it failed. The output was:
Status: Resolving address of www.mySite.com
Status: Connecting to IPADDRESS...
Status: Connection established, waiting for welcome message...
Error: Connection timed out
Error: Could not connect to server
Status: Waiting to retry...
Status: Resolving address of www.mySite.com
Status: Connecting to IPADDRESS...
Status: Connection established, waiting for welcome message...
Error: Connection timed out
Error: Could not connect to server
Looks like you have server issues, but if you'd like the Python program to error out instead of waiting forever for the server, you can specify a timeout kwarg to ftplib.FTP. From the docs (https://docs.python.org/2/library/ftplib.html#ftplib.FTP)
class ftplib.FTP([host[, user[, passwd[, acct[, timeout]]]]])
Return a new instance of the FTP class. When host is given, the method call connect(host) is made. When user is given, additionally
the method call login(user, passwd, acct) is made (where passwd and
acct default to the empty string when not given). The optional timeout
parameter specifies a timeout in seconds for blocking operations like
the connection attempt (if is not specified, the global default
timeout setting will be used).
Changed in version 2.6: timeout was added.