POST method of httplib python gives an error "socket.gaierror: [Errno -2] Name or service not known" - httplib

The following code throws an error "socket.gaierror: [Errno -2] Name or service not known".
import httplib, urllib
attrs = urllib.urlencode({"username":"admin", "password":"admin"})
conn = httplib.HTTPSConnection("https://x.x.x.x:8181")
conn.request("POST", "/login", attrs)
response = conn.getresponse()
print response.status, response.reason
I don't want to use urllib2 module.
Could anybody help me?...
How to save the state of that server?, so that next time i directly post the values for the uri.

I think you are not specifying the non-default port correctly:
http://docs.python.org/release/2.6.7/library/httplib.html#httplib.HTTPSConnection
Try this instead:
conn = httplib.HTTPSConnection("https://x.x.x.x",port=8181)

Try the following code:
conn = httplib.HTTPSConnection("x.x.x.x",port=8181)

I was getting a similar error with httplib.HTTPConnection, I found changing the url from "http://x.x.x.x" to "x.x.x.x" worked for me. Try removing the "http://" or "https://".
conn = httplib.HTTPSConnection("x.x.x.x:8181")

Related

http_request succeeds but Groovy code gets 401

I was using the HTTP Request Plugin to make an API call to my Bitbucket server.
The following call returns the desired result:
def my-url = "http://my-username:my-password#my-bitbucket-server.com:7990/rest/api/1.0/my-project/pull-request-10"
def response = http_request my-url
However, I had an issue with the HTTP Request Plugin, because it prints my password in plain text in the logs.
Therefore, I tried doing the same call from a groovy script:
def response = new URL(my-url).getText()
But for this I am getting a 401 server response.
Any idea why this time, the call fails?
You're trying to apply Basic auth using almost plain Java. You have to generate your auth key and attach it to the request headers. Try:
String addr = 'my-bitbucket-server.com:7990/rest/api/1.0/my-project/pull-request-10'
String authString = 'my-username:my-password'.getBytes().encodeBase64().toString()
def conn = addr.toURL().openConnection()
conn.setRequestProperty( "Authorization", "Basic ${authString}" )
def feed = new XmlSlurper().parseText( conn.content.text )
Hope this would help!

Ruby on rails: error in sending xml message

I try to send a xml file to a web service, but it's not working. The web service supplier has no idea.
If you read the error message, it looks like there is a wrong soap version used, but the supplier tried it with the same xml file and he had no problems with this file. I have no idea what's wrong.
The code:
#Declaration
host = "bar.foo.nl";
path = "/services/setu.asmx";
port = 443;
username = "xxx"
password = "yyy";
ssl = true;
#Create connection
req = Net::HTTP::Post.new(path)
req.basic_auth(username, password)
http = Net::HTTP.new(host, port)
http.use_ssl = ssl
#send file
res = http.request(req, 'D:/test.xml')
#show result
puts res.code
puts res.body
EDIT: The xml file: XML FILE
The error (500 code):
Possible SOAP version mismatch: Envelope namespace
http://ns.hr-xml.org/2007-04-15 was unexpected. Expecting
http://schemas.xmlsoap.org/soap/envelope/.
I don't see any soap declarations in the file you've uploaded, and it looks like the service you're contacting requires it.
Start with http://www.w3schools.com/xml/xml_soap.asp and rework your content to be wrapped in a soap envelope.

Adding port to zf2 http client uri

I want to connect to http://10.11.12.1:8083 so I use this code snippet:
public function tempAction(){
$client = new Client();
$client->setAdapter('Zend\Http\Client\Adapter\Curl');
$client->setUri('http://10.11.12.1:8083');
$response = $this->getResponse();
$result = $client->send();
$body = $result->getBody();
Debug::dump("DEBUG: " . $body);
Anyway, the error message I got is: 'Error in cURL request: connect() timed out!'. I tried to connect to the website http://10.11.12.1:8083 by browser and it worked - I was able to see the expected user interface. Moreover I was able to use the code snippet to connect to a website without an explicitely named port. I guess I need to change my way of adding the port to the url?
I am using ZendFramework 2.
The way I found to add port is to use Zend\Uri\Uri
example
$uri = new Uri();
$uri->setHost($this->config['server']);
$uri->setPort($this->config['port']);
$uri->setPath('/jsonrpc');
Then in your client:
$client = new Client($uri->toString(), array());
There is probably a better way but that worked.

luasoket http request got "connection refused"

I am trying to use luasocket to make http "GET" request to "https://buy.itunes.apple.com/verifyReceipt" , it yields a "connection refused" , while I can access this URL from the the web browser either use python httplib.
I doubted it is because the HTTPS protocal , but if i replace url with "https//www.google.com" , it works ok.
so any1 has ideas on what the problem is ? much thx for ur answers
This is the code:
local http = require("socket.http")
URL = "https://buy.itunes.apple.com/verifyReceipt"
local response, httpCode, header = http.request(URL)
print(response, httpCode, header)

WSDL using soapclient

Need to access a webservice using soapclient.I have the following settings.
ini_set('default_socket_timeout', 120);
$client = new SoapClient(
"http://example.com/OnlineOrderProcessingWS.asmx?WSDL",
array('proxy_host' => "proxy url",
'proxy_port' => proxy port
)
);
$param=array("varname1"=>'value1',"varname2"=>'value2');
$result = $client->CustomerOrder($param);
print_r($result);
Executing this script throwing
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers.
The most common reason for this error seems to be a timeout while waiting on the service response. You already adjust your socket_timeout to 120, but might want to try an even higher value. How long does it take for the error to be returned?

Resources