2015-08-31 34 views
2

就遇到了這個問題,試圖調用braintree.ClientToken.generate()從谷歌App Engine應用程序,在運行dev_appserver.py瓶。 dev_appserver.py目前無法進行傳出SSL連接。在進行以上布倫特裏調用產生解決方法dev_appserver.py無法作出SSL請求

ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

呼叫工作在一個真實的環境GAE。它用在我的一個觀點中,所以當它失敗時,它會打破我的整個網站流程,出現上述500錯誤。我該如何解決這個問題,以便在當地環境中繼續發展?

回答

1

我在布倫特裏工作。如果您有更多問題,可以隨時撥打contact our support team

有關GAE上Braintree Python庫的幫助,請參閱this example on my GitHub。要回答你的問題,你可以force the dev server to use the real Python socket library,所以SSL連接工作:

try: 
    # This is needed to make local development work with SSL. 
    # This must be done *before* you import the Braintree Python library. 
    # See http://stackoverflow.com/a/24066819/500584 
    # and https://code.google.com/p/googleappengine/issues/detail?id=9246 for more information. 
    from google.appengine.tools.devappserver2.python import sandbox 
    sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket'] 

    import sys 
    # this is socket.py copied from a standard python install 
    import stdlib_socket 
    sys.modules['socket'] = stdlib_socket 
except ImportError as e: 
    print(e) 
+0

這是一個不同的問題(我認爲)的答案。如果我理解正確,這將啓用到dev_appserver.py的傳入SSL連接,而不是傳出的連接。我遇到的問題是dev_appserver無法創建傳出的SSL連接。當所有我能找到的與我的問題有關的所有問題都是這個答案時,我感到非常沮喪,當然,我試圖無利可圖,遍佈整個互聯網。 – brandones

+0

@brandones你錯了。此修復程序專門用於啓用傳出SSL連接。 – agf

+0

沒有爲我工作。這個修補程序有幾個變種,我也試過。我只是不斷得到相同的錯誤 - 「ConnectionError:('連接中止。',錯誤(13,'權限被拒絕'))' – brandones

1

如果你有一些變量全局您的應用程序,當你在運行dev_appserver.py與對應,您可以創建條件對變量失敗方法的模擬。

在我的情況下,該變量被稱爲env_conf.FLASK_CONF。我用下面的代碼來模擬braintree生成調用。

# Imports 
import braintree 
import env_conf 
from flask import render_template 

# Mock Braintree in DEV environment 
if env_conf.FLASK_CONF == 'DEV': 
    from functools import partial 
    def mock_generate(self): 
     return 'foobarbaz123' 
    braintree.ClientToken.generate = partial(mock_generate, braintree.ClientToken()) 

# Add payment handler 
def add_payment(): 
    token = braintree.ClientToken.generate() 
    return render_template('add-payment.html', 
          braintree_client_token=token) 

的想法一般爲:

import problem_function 
if DEV_ENVIRONMENT: 
    def mock_problem_fcn(): 
     return 'expected response' 
    problem_function = mock_problem_function 

problem_function() 
相關問題