function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SLockardSLockard 

Beatbox EOF occurred

Hello everyone,

 

We are trying to use Beatbox and connect to salesfroce through a https connection with a proxy, but are getting an error: ssl.SSLError : EOF occured in violation of protocol .. Here is some of the code:

 

import os
import sys
import beatbox
import xmltramp
import datetime
import urllib

sf = beatbox._tPartnerNS
svc = beatbox.Client()
beatbox.gzipRequest=False

class BeatBoxDemo:

	def login(self, username, password):
		self.password = password
		loginResult = svc.login(username, password)
		
		return loginResult
		
		
demo = BeatBoxDemo()
loginResult = demo.login('username@website.com', 'passandsecuritytoken')

newPost = { "ParentID" : "groupIdHere", "Body" : "bodyText", "Type" : "TextPost", "type" : "FeedItem" }
r = svc.create(newPost)

if str(r[sf.success]) == 'true':
	print "success"
else:
	print "error"
print "error :" + str(r[sf.errors][sf.statusCode]) + ":" + str(r[sf.errors][sf.message])





# in beatbox 
class Client:
	def __init__(self):
		self.batchSize = 500
		self.serverUrl = "test.salesforce.com/services/Soap/u/21.0"
		self.__conn = None
		
		
def makeConnection(scheme, host):
	if forceHttp or scheme.upper() == 'HTTP':
		return httplib.HTTPConnection(host)
	user = 'username';passwd='password'
	#host='test.salesforce.com';port=443
	port=443
	phost='proxy.address.com';pport=80	
	user_pass=base64.encodestring(user+':'+passwd)
	user_pass=user_pass.replace('\n', '')
	proxy_authorization='Proxy-authorization: Basic '+user_pass+'\r\n'
	proxy_connect='CONNECT %s:%s HTTP/1.0\r\n'%(host,port)
	user_agent='User-Agent: python\r\n'
	proxy_pieces=proxy_connect+proxy_authorization+user_agent+'\r\n'
	proxy=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	proxy.connect((phost,pport))
	proxy.sendall(proxy_pieces)
	response=proxy.recv(8192)
	status=response.split()[1]
	#if status!=str(200): raise 'Error status=',str(status)
	sock=ssl.wrap_socket(proxy)
	f=httplib.HTTPConnection('localhost')
	f.sock=sock
	#f.Url=host
	print f
	return f
	
	

 If I change a few things around sometimes I also get an UNKNOWN EXCEPTION: destination url was not reset ..

Any help would be greatly appreciated!

Best Answer chosen by Admin (Salesforce Developers) 
SLockardSLockard

I managed to find a solution after some more tinkering, here is the code to help anyone else who had/has this problem:

import os
import sys
import beatbox
import xmltramp
import datetime
import urllib

sf = beatbox._tPartnerNS
svc = beatbox.Client()
beatbox.gzipRequest=False

class BeatBoxDemo:

	def login(self, username, password):
		self.password = password
		loginResult = svc.login(username, password)
		
		return loginResult
		
		
demo = BeatBoxDemo()
loginResult = demo.login('username@website.com', 'passandsecuritytoken')

newPost = { "ParentID" : "groupIdHere", "Body" : "bodyText", "Type" : "TextPost", "type" : "FeedItem" }
r = svc.create(newPost)

if str(r[sf.success]) == 'true':
	print "success"
else:
	print "error"
        print "error :" + str(r[sf.errors][sf.statusCode]) + ":" + str(r[sf.errors][sf.message])





# in beatbox 
class Client:
	def __init__(self):
		self.batchSize = 500
		self.serverUrl = "test.salesforce.com/services/Soap/u/23.0"
		self.__conn = None


def makeConnection(scheme, host):
	if forceHttp or scheme.upper() == 'HTTP':
		return httplib.HTTPConnection(host)
	
	user = 'user.name';passwd='*********' ## Enter in a real username and password !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	port=443
	phost='proxy.proxyhost.com';pport=80	
	user_pass=base64.encodestring(user+':'+passwd)
	user_pass=user_pass.replace('\n', '')
	proxy_authorization='Proxy-authorization: Basic '+user_pass+'\r\n'
	proxy_connect='CONNECT %s:%s HTTP/1.0\r\n'%(host,port)
	user_agent='User-Agent: python\r\n'
	proxy_pieces=proxy_connect+proxy_authorization+user_agent+'\r\n'
	proxy=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	proxy.connect((phost,pport))
	proxy.sendall(proxy_pieces)
	response=proxy.recv(8192)
	status=response.split()[1]
	sock=ssl.wrap_socket(proxy,ssl_version=ssl.PROTOCOL_TLSv1)
	f=httplib.HTTPSConnection('localhost')
	f.sock=sock

	print f
	return f

 The code is pracically the same, the missed indent for printing the errors may have been the source.

All Answers

SuperfellSuperfell

There's a fork on github with https proxy support, i haven't tried it. https://github.com/bobf/Beatbox/commits/master

SLockardSLockard

Thanks for the link, but even with that version I am now getting the addrinfo error again.

SLockardSLockard

I managed to find a solution after some more tinkering, here is the code to help anyone else who had/has this problem:

import os
import sys
import beatbox
import xmltramp
import datetime
import urllib

sf = beatbox._tPartnerNS
svc = beatbox.Client()
beatbox.gzipRequest=False

class BeatBoxDemo:

	def login(self, username, password):
		self.password = password
		loginResult = svc.login(username, password)
		
		return loginResult
		
		
demo = BeatBoxDemo()
loginResult = demo.login('username@website.com', 'passandsecuritytoken')

newPost = { "ParentID" : "groupIdHere", "Body" : "bodyText", "Type" : "TextPost", "type" : "FeedItem" }
r = svc.create(newPost)

if str(r[sf.success]) == 'true':
	print "success"
else:
	print "error"
        print "error :" + str(r[sf.errors][sf.statusCode]) + ":" + str(r[sf.errors][sf.message])





# in beatbox 
class Client:
	def __init__(self):
		self.batchSize = 500
		self.serverUrl = "test.salesforce.com/services/Soap/u/23.0"
		self.__conn = None


def makeConnection(scheme, host):
	if forceHttp or scheme.upper() == 'HTTP':
		return httplib.HTTPConnection(host)
	
	user = 'user.name';passwd='*********' ## Enter in a real username and password !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	port=443
	phost='proxy.proxyhost.com';pport=80	
	user_pass=base64.encodestring(user+':'+passwd)
	user_pass=user_pass.replace('\n', '')
	proxy_authorization='Proxy-authorization: Basic '+user_pass+'\r\n'
	proxy_connect='CONNECT %s:%s HTTP/1.0\r\n'%(host,port)
	user_agent='User-Agent: python\r\n'
	proxy_pieces=proxy_connect+proxy_authorization+user_agent+'\r\n'
	proxy=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	proxy.connect((phost,pport))
	proxy.sendall(proxy_pieces)
	response=proxy.recv(8192)
	status=response.split()[1]
	sock=ssl.wrap_socket(proxy,ssl_version=ssl.PROTOCOL_TLSv1)
	f=httplib.HTTPSConnection('localhost')
	f.sock=sock

	print f
	return f

 The code is pracically the same, the missed indent for printing the errors may have been the source.

This was selected as the best answer