Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin isn't working behind proxy #42

Open
stese opened this issue Sep 10, 2014 · 22 comments
Open

Plugin isn't working behind proxy #42

stese opened this issue Sep 10, 2014 · 22 comments

Comments

@stese
Copy link

stese commented Sep 10, 2014

If you are using sublime text behind a company proxy, you basically have to set the proxy settings per module right to get this module working right now.

I had to set the company proxy for example for the plugin package control in the settings of the package control, because the sublime own proxy settings were ignored (see https://sublime.wbond.net/docs/settings#setting-http_proxy).

The possibility to set custom proxy settings for this module would be nice. For now, the plugin isn't working behind a proxy, even if the .bash_profile of the user or something similar is set up correctly.

@bordaigorl
Copy link
Owner

This is certainly something the plugin should support.
I included it in the todo list for next release but I cannot promise it will be done soon.
If somebody is willing to help I would be glad to accept pull-requests.
Thanks for the feedback!

@bordaigorl
Copy link
Owner

For future reference: evernote/evernote-sdk-python3#6

@bordaigorl bordaigorl modified the milestones: Version 3, Version 2.5.3 Sep 13, 2014
@bordaigorl
Copy link
Owner

I did some experiments and it would seem that the Evernote library for Python 3 does not support proxies, unlike the one for Python 2.
Adapting it so it works for Python 3 is not trivial. It requires some knowledge of the inner workings of the Thrift library. I tried a quick patch but it does not seem to work.
I consider this a rather hi priority feature but one that requires some expertise that I lack.
I hope @rekotan or other contributors will be able to help at some point to get this to work.

@tommarien
Copy link

@bordaigorl Is there atm any known workaround ?

@bordaigorl
Copy link
Owner

@tommarien Not that I know of: I cannot reproduce the issue with the networks available to me.
Additionally it's the Thrift protocol which seems to go wrong and it's a generated library used by the Evernote SDK, so it's something the Evernote team should eventually fix but it's certainly something out of my reach for the moment...
I'd be happy to accept patches from somebody knowledgeable on Thrift!

@tommarien
Copy link

@bordaigorl what about using tools like SquidNT and fiddler to check if the code uses the proxy or not ?

@zwpaper
Copy link

zwpaper commented Dec 30, 2014

Is there now a possible way to make the plugin work behind proxy for now, even a hard one?
I need it so much, but I have to work behind the proxy because of the company network.

@bordaigorl
Copy link
Owner

@zwpaper It would seem that the problem arose only after updating to ST 3065 so a possible workaround would be to downgrade your ST3 version...
Should you decide to try this could you report back if it solved the issue?

@zwpaper
Copy link

zwpaper commented Jan 1, 2015

it doesn't work...I have tried 3059 and 3047, neither of them work...looks like the same problem.

Both test in Windows and Ubuntu 14.04

Evernote plugin 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
error: Evernote plugin error, please contact developer at
https://github.com/bordaigorl/sublime-evernote/issues

@generic-user
Copy link

Hi,

I have little knowledge of how python works, put I have have inspected some library's that are sublime plugins. And from what I can see the problem lies within the Evernote API for Python 3.x, not in the Python itself.

Why do I think this?
Well ..., if I install this plugin (sublime-evernote), it gets downloaded by the package control PLUGIN, so that means Python must be using my proxy credentials without a problem.

I thing u can clearly see this in the Package Control code here: link to Git-Hub

Would it be possible to go and look in the thrift library, find where they declare a connection, and inject the desired proxy settings?

I would try and do it myself, but don't expect me to make a swift progress, I would have to be learning a new programming language, and time is not on my hand ...

Hopefully I am pointing in the right direction and some Python Guru could create a pull request for the Thrift library.

My 2 cents, BC

@tauren
Copy link

tauren commented Jan 12, 2015

Too bad there is no easy fix to this. I will try it out at being my work proxy tomorrow, as I imagine it will affects me as well. I just got a pretty awesome evernote/sublime workflow going at home and was hoping to use it at work too.

@generic-user
Copy link

@tauren
Jeah, I have the same problem, set up my workflow at home, and thought it was awsome, then I got at work and --> Doh! Not working 👎

@tauren
Copy link

tauren commented Jan 12, 2015

@BattoorCjorn So I just got in to work and tried it out. I'm not sure why, but everything seems to work properly and I didn't do anything special. I'm on OSX and have environment variables such as HTTP_PROXY configured properly.

@generic-user
Copy link

@tauren
Yeah I know, it only occurs when the proxy has been configured within Internet Explorer, and not in the environment variables..., this is in a government managed network, so I'ts not up to me to fiddle with the environment variables. That is why I would like for applications to let us set a proxy overwrite ...

@bordaigorl
Copy link
Owner

@BattoorCjorn just to check, what happens if you set the evironment vars locally?
Like in a Batch file with set and starting sublime?

@generic-user
Copy link

@bordaigorl
As it is in a "corporate environment", the only variables I can set are the user defined environment variables, not the system defined variables (u need to be admin for that).

So to answer the question, nothing special, and that is because Sublime Text only looks at the SYSTEM defined vars, instead of the SYSTEM + USER DEFINED vars ...

This is the same problem I have with applications that use PATH environment variables to locate certain resources ... that never works, and I always need to set the PATH's to the resource files manually in the setting file of plugin itself.

@bordaigorl
Copy link
Owner

I see. Thanks for the clarification. Unfortunately I am not very experienced with this aspect.
Does anybody know if messing with os.environ from within ST can help?

@generic-user
Copy link

No, it won't help becouse the thrift (Phyton 3.x) library used in the evernote API, does not use these settings.

The problem is that when they Ported thrift to 3.x, they left proxy support out of it.

Constructors THttpClient

Lets look at the old 2.x implementation of the Thttpclient:

class THttpClient(TTransportBase):

    """Http implementation of TTransport base."""

    def __init__(
        self,
        uri_or_host,
        port=None,
        path=None,
        proxy_host=None,
        proxy_port=None
    ):
        """THttpClient supports two different types constructor parameters.
        THttpClient(host, port, path) - deprecated
        THttpClient(uri)
        Only the second supports https."""

        """THttpClient supports proxy
        THttpClient(host, port, path, proxy_host, proxy_port) - deprecated
        ThttpClient(uri, None, None, proxy_host, proxy_port)"""

So if we look at the constructor u can clearly see that in Python 2 support for proxy's was added, and used.

Now if u look at the 3.x constructor u notice that support has been teared down:

class THttpClient(TTransportBase):
  """Http implementation of TTransport base."""

  def __init__(self, uri_or_host, port=None, path=None):
    """THttpClient supports two different types constructor parameters.
    THttpClient(host, port, path) - deprecated
    THttpClient(uri)
    Only the second supports https.
    """

So that means even if u would be able to set the environment HTTP_PROXY variable, you would not be able to pass it to the constructor of the ThttpClient.

Where is Thrift Python?

So now that we know what needs to be changed, where do we change it?
Found it here

@bordaigorl
Copy link
Owner

@BattoorCjorn yes, I noticed that as well but since THttpClient uses http.client I was wondering if there was a way to just set the http.client proxy setting globally.
in fact I did some experiments by manually porting the proxy related code of the new version to the Thrift shipped with the EvernoteSDK.
I cannot get past a "Message length exceeded" error. This error seems to be generated by the server in response to a request forwarded by the proxy (I am using a simple local proxy based on BaseHTTPServer for testing). At the moment I still do not know what is causing the problem.

As for updating Thrift, it would seem you need some sources we do not have from which Thrift generates the library....

@generic-user
Copy link

@bordaigorl
OK, so this seems to work behind my corporate firewall ...

There are 4 layers when making http requests, Thttpclient uses http.client uses request uses sockets.

The example uses the request layer. And this is what it says about that layer in the docs:

urllib.request.install_opener(opener)
Install an OpenerDirector instance as the default global opener. Installing an opener is only necessary >if you want urlopen to use that opener; otherwise, simply call OpenerDirector.open() instead of >urlopen(). The code does not check for a real OpenerDirector, and any class with the appropriate >interface will work.

So will it work to set the global opener on the urllib.request.install_opener(opener), and then hope that when a call will be made in the http.client, that proxy will be used ?

Pff ...

OK so I tried it, apparently the "the default global opener" isn't as global as It's name presumes. I'm
out of fireworks here, guess i'll have to be patient and wait for a fix.

@thorstenhuhn
Copy link

I would also love to see this problem fixed but I have a workaround to share:
Alternative A: I was able to reroute the ST plugins outgoing traffic transparently through the proxy using [https://www.proxifier.com/index.htm] for Mac which is also available for Windows and allows 30 days trial. Unfortunately 40 $ is pretty much money having only this one use case.
Alternative B (Mac only): The same thing works using [https://github.com/csujedihy/proximac] but I have to disable System Integrity Protection which leaves a bad taste, too.

@qunwang6
Copy link

qunwang6 commented Mar 7, 2020

anybody can fix this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants