(502) Bad Gateway PhantomJS driver initialize - c#

I'm using Selenium.WebDriver 3.8.0 in .NET Core app and trying to initialize PhantomJS driver like this:
PhantomJSDriverService driverService = PhantomJSDriverService.CreateDefaultService("<path to PhantomJS binary file>", "phantomjs");
PhantomJSOptions options = new PhantomJSOptions();
driverService.Proxy = "{my proxy address}:{port}";
driverService.ProxyType = "http";
IWebDriver driver = new PhantomJSDriver(driverService, options);
When I run on CentOS:
[INFO - 2018-01-15T13:28:48.526Z] GhostDriver - Main - running on port 46847
The remote server returned an error: (502) Bad Gateway.
The remote server returned an error: (502) Bad Gateway. ... The remote server returned an error: (502) Bad Gateway.
If I use the default constructor:IWebDriver driver = new PhantomJSDriver();, the same error occurs.
In CentOS system proxy is configured in /etc/profile like this:
MY_PROXY_URL="{my proxy address}:{port}"
HTTP_PROXY=$MY_PROXY_URL
HTTPS_PROXY=$MY_PROXY_URL
FTP_PROXY=$MY_PROXY_URL
http_proxy=$MY_PROXY_URL
https_proxy=$MY_PROXY_URL
ftp_proxy=$MY_PROXY_URL
export HTTP_PROXY HTTPS_PROXY FTP_PROXY http_proxy https_proxy ftp_proxy
What could be the problem? I learned all the queries in Google about Selenium, PhantomJS and CentOS

Cause of 502 Bad Gateway Errors
Bad Gateway errors are often caused by issues between online servers that you have no control over.
Source
There is probably some issue on the server end, so as you see, there is probably nothing you can do unless the server is yours. I doesn't have to do with your constructor.
However, sometimes, there is no real issue but your browser thinks there is one thanks to an issue with your browser, a problem with your home networking equipment, or some other in-your-control reason.
Source
On the other hand, it might be an issue with your configuration. There are some things you can do and try to fix it here: Fix 502 Bad Gateway Error, they might help you out if it's really a problem on your end.

Related

.Net Connection to Bolt URI failing with Neo4jClient but not Neo4j.Driver

I have been connecting .Net Core code from within a Docker container to a Neo4j DB. I tried using Neo4jClient first but ran into issues with the http connection out of the docker container. I then tried the Neo4j.Driver directly with the bolt connection using host.docker.internal to alias localhost. This worked fine. I swapped back to Neo4jClient with bolt (again from within Docker) but its failing with.
Thanks for any help.
Neo4j.Driver.V1.ServiceUnavailableException
HResult=0x80131500
Message=Connection with the server breaks due to SecurityException: Failed to establish encrypted connection with server bolt://host.docker.internal:7687/.
Source=Neo4j.Driver
Update:
Following Chris Skardon's help below. I switched on ssl for bolt as per section Example 11.2. Enable Bolt SSL.
As per instructions here at Neo4j
The code below using Neo4j.Driver directly works and updates the DB with 12 organisations.
Its running from within a .Net Core Docker container and using host.docker.internal. I would have expected this not to work without the Encryption config. But it does.
IDriver driver = GraphDatabase.Driver("bolt://host.docker.internal:7687", AuthTokens.Basic("neo4j", "xxxxx"));
IAsyncSession session = driver.AsyncSession(o => o.WithDatabase("neo4j"));
This code using Neo4jClient doesn’t work. I was originally running it within a docker container as above and thought that might be it. But still have a problem with no container
IDriver driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "xxxxx"), Config.Builder.WithEncryptionLevel(EncryptionLevel.Encrypted).ToConfig());
var client = new BoltGraphClient(driver);
The exceptions are:
Connection with the server breaks due to SecurityException: Failed
to establish encrypted connection with server
bolt://localhost:7687/.'
IOException: Authentication failed because
the remote party has closed the transport stream.
Nothing appears in the Neo4j logs. I don't have any specific code in the .Net Core API code for supporting SSL and googling the 2nd exception comes back with a lots of incorrect TLS results. So am exploring that.
The 4.x versions of Neo4j require Encryption to be set, Neo4jClient doesn't actually provide an easy way to do this, so you'd need to pass in an IDriver instance, like so:
var driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "neo"), Config.Builder.WithEncryptionLevel(EncryptionLevel.None).ToConfig());
var client = new BoltGraphClient(driver);
EDIT
I've been testing this - and the problem is actually the opposite - you need to turn the encrpytion level to 'None' - unless you actually have an SSL cert setup

'No connection could be made because the target machine actively refused it'

I am working on a 'Smart Device Project' using .Net Framework 3.5. I am trying to connect to some Java SOAP services on a remote server.
In order to do that, I added 'Web References' to my project.
When I try to call my web service I get a WebException 'Unable to connect to the remote server' with the inner exception being 'No connection could be made because the target machine actively refused it'.
I searched quite a lot on the Web and StackOverflow and found a lot of ASP configuration and 'Unavaliable port' answers, but as I have another application using the exact same Service successfully, I can't get why the new one isn't getting through (It did sometimes through my tests so I suppose my client implementation isn't that bad)
I tried to look if there was some connection issue on the port by using some TcpClient:
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
try
{
client.Connect("myServerName", 8087);
MessageBox.Show("Success");
} catch (Exception ex)
{
MessageBox.Show("Failure");
}
finally
{
client.Close();
}
This connection succeed.
Here is a sample on how I call my WebService:
WSServiceExtended srv = new WSServiceExtended();
srv.Proxy = new System.Net.WebProxy();
ServeurWSI wsi = new ServeurWSI();
srv.Url = "http://myServerName:8087/myServerApp/services/myService";
wsr = srv.login(wsi);
The service is called 'Extended' because I overrided the auto-generated one in order to add Cookie managment since I am using the Compact Framework. Following the sample in this thread:
https://social.msdn.microsoft.com/Forums/en-US/34d88228-0b68-4fda-a8cd-58efe6b47958/no-cookies-sessionstate-in-compact-framework?forum=vssmartdevicesvbcs
EDIT:
I made some new tests with the Web references and got it to work.
When I add the Web Reference, I have to put some Url to the Web Service. When I set it with the actual hostname instead of the 'localhost' everything is fine.
But then, since I set it manually to the real address just before the call, it shouldn't matter
srv.Url = "http://myServerName:8087/myServerApp/services/myService";
EDIT2:
I might have forgotten some specifics about my environnement.
The Web Services are exposed on my computer on some Tomcat Server.
The application I am working on is also developped on this computer (That's why I can add Web References by putting 'localhost' in the address)
The application is then deployed on a distant device (Windows CE) that will make calls the Web Services through WIFI (There, localhost wouldn't work then)
I tried calling the Web services from other computers successfully.
I'm beginning to think that there might be some differential between the called Url and the one that is set, otherwise, how would I have a difference in behaviour such as the one described in the first edit?
EDIT3:
Well..Seems like it's not a network issue but a .Net compact framework (usage?) issue...
The Url property of the Web Service implementation is simply ignored and the one in the Reference.cs is used in place.
If someone had some idea on how I could troubleshot this, I would really appreciate it.
That error means that you reached a server and the server said "no way". So you're either hitting the wrong server or the wrong port.
I find the telnet client is useful for testing stuff like this. From the command line, you can do:
telnet [servername] [port]
So something like:
telnet myServerName 8087
If it goes to a blank screen, then it connected successfully. If it does not connect, it'll tell you.
The telnet client is no longer installed by default in Windows 7+, so you'll have to install it. See here for instructions: https://technet.microsoft.com/en-ca/library/cc771275
If the connection does open, you could paste in an actual HTTP request to see what happens. A simple GET would look something like this:
GET /myServerApp/services/myService HTTP/1.1
Host: myServerName:8087
One reason for this error can be that the service binds to only a certain IP address. It could well be that the service only listens on the IP that is assigned to the host name, but not on the localhost IP (127.0.0.1).
For example:
If the host myServerName has the public IP 192.168.0.1, your service can choose to listen on all IPs assigned to the host (sometimes specifying 0.0.0.0), or it can specifically listen on 192.168.0.1 only. In that case you will not be able to connect through 127.0.0.1, because the service simply doesn't listen on that IP.
You can "use" this inverse of this feature to make a service accessible only to local clients, not on the public IP-Address, by listening on 127.0.0.1 only, but not on the public IP. This is sometimes used on Linux for example to make MySQL only accessible on the host itself.
I was starting to forget this post but I finally found the problem that was messing things up and it has nothing to do with programmation.
I was doing the calls while the device was connected to the computer via the 'Windows Mobile Device Center' allowing to access the device from Windows.
While connected, the host provided is ignored and all calls on the specified port are handled by the connected computer.
Disconnecting the device allows to communicate properly...

Microsoft's url for the Exchange powershell schema is not valid anymore

I am trying to create a remote connection to an exchange Powershell hosted on IIS 8.5 - Windows Server 2012 R2.
Here's my code :
var connInfo = new WSManConnectionInfo(
new Uri("https://xxx/PowerShell"),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credentials);
It look like the Microsoft's Schemas url is not valid anymore. If I navigate to http://schemas.microsoft.com/powershell/Microsoft.Exchange, I have this :
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
And when I try to open my connection, I have this error :
Connecting to remote server failed with the following error message : The WinRM client received an HTTP bad request status (400), but the remote service did not include any other information about the cause of the failure.
Is it possible the url changed ? I trid to find a topic about it, but I found no trace of a change...
The schema uri doesn't have to be 'valid' in the sense you don't have to be able to navigate to it. I know I'm not explaining it properly but it's more a reference than a valid location.
The error you're receiving is actually referring to the uri you have for your Exchange Server. If you aren't connecting to an Exchange Server the connection will error.

BrowserMob Proxy - The remote server returned an error: (404) Not Found

I'm trying to use BrowserMob Proxy with Selenium in C#.
I've tried this solution here:
http://www.adathedev.co.uk/2012/02/automating-web-performance-stats.html
And my code looks like this:
Server server = new Server(#"path_to\\browsermob-proxy.bat");
server.Start();
Client client = server.CreateProxy();
client.NewHar("test");
var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
var profile = new FirefoxProfile();
profile.SetProxyPreferences(seleniumProxy);
IWebDriver driver = new FirefoxDriver(profile);
When I run the test I get the following error:
System.Net.WebException: The remote server returned an error: (404) Not Found.
It fails at the third line.
Any suggestions on how to get this working?
If you can post a more detailed stack trace, that would be useful, along with the remote host you're trying to connect to. In the meantime a few things to try are:
Check the address you're requesting. It seems you're getting a 404 -- can you hit it through a browser without the proxy?
Make sure browsermob-proxy.bat is installed at the path on line 1 (is it really in a subdirectory of the working directory called "path_to"?)
Check your write permissions in the temp directory, which is %TEMP% or %TMP% on Windows. BMP writes temporary files there.
Grab the latest source and build the .bat file. The instructions are on the browsermob-proxy github page at the bottom (under Creating the batch files from source).
Hope that helps!
This is most likely because your Jetty service is not actually running, did you get a message from BrowserMob batch file saying it couldn't run? In my case it was a situation where the port (by default is set to 8080) but I had something else listening on that port. To fix this, you can pass an optional port number.
var server = new Server(#"C:\path\to\bin\browsermob-proxy.bat", 9090);
I had same problem on python. When I had tried to get content of localhost:8080 I got 404 error. It turned out that my other application was using same 8080 port. So I found PID typing in cmd: netstat -o -n -a | findstr :8080. Then I just terminated process with this PID and browsermob gave me well HAR.

Cannot access wcf service hosted on iis from php with soapclient

This has been really painful for the last few hours and I just have no more ideas what to do.
Tried many solutions that I found on here without any luck...
I have an iis server that is hosting a wcf web service. Simple stuff.
I can connect to this (example: http://mydomain.com/Service.svc?wsdl) from the iis server and all other computers without any problems.
So I went on to make a php client on my computer - (using xampp via localhost) - (not on the iis server)
$wcfClient = new SoapClient('http://mydomain.com/Service.svc?wsdl');
$args = //input data
$response = $wcfClient->GetData($args);
print_r($response->GetDataResult->Post);
This works perfect. No problems at all. It returns all the data... Then I went on to upload this to my hosting account. This is the error I keep getting.
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ....
I have no more ideas. Disabled firewall, changed web.config a million times and still no luck. I tried the file_get_contents method to see what's up. I keep getting:
failed to open stream: Connection refused
I just fixed this by changing the port to 80 on the iis server...

Categories