python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.06k stars 505 forks source link

How to disable ssl cert verification #480

Closed yurenji closed 5 years ago

yurenji commented 5 years ago

Is there a way to disable SSL? I found it in a similar project:

image

It will be very helpful if this can be supported

aaugustin commented 5 years ago

connect accepts the same ssl argument than create_connection: https://docs.python.org/3/library/asyncio-eventloop.html?highlight=create_connection#asyncio.loop.create_connection

Create an insecure ssl.SSLContext and pass it as the ssl argument.

aaugustin commented 5 years ago

Also: please don't do this, creating a certificate and building a SSL context that trusts it is super easy, there's even an example here: https://github.com/aaugustin/websockets/blob/4e7a82eeec4621f7a6d99d43aa0a995b70382992/tests/test_client_server.py#L43-L46

yurenji commented 5 years ago

Thanks for the reply. I am testing with binance websocket. I tested another project without ssl certificate, but not sure how to make it work with ssl. Can you give me some guide, here is my code:

url = 'wss://stream.binance.com:9443/stream?streams=btcusdt@depth10'
async def hello():
    ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
    ssl_context.load_verify_locations(
        pathlib.Path(__file__).with_name('test_localhost.pem'))
    async with websockets.connect(url, ssl=ssl_context) as websocket:
        greeting = await websocket.recv()
        print(f"< {greeting}")
asyncio.get_event_loop().run_until_complete(hello())

I created a self signed pem, but seems I was not able to read anything from websocket.

aaugustin commented 5 years ago

Sorry, I have to walk out of this discussion: https://websockets.readthedocs.io/en/stable/contributing.html#bitcoin-users

bgits commented 4 years ago

Sorry, I have to walk out of this discussion: https://websockets.readthedocs.io/en/stable/contributing.html#bitcoin-users

@aaugustin Your objection is supported by many in crypto community and there is active research in making them more sustainable. I would point you towards the Ethereum roadmap and it's plans to move away from proof-of-work completely to the much more sustainable model of proof-of-stake.

aaugustin commented 4 years ago

I'm aware of this.

Tell me when the combined carbon footprint of all cryptocurrencies has dropped down to a non-bullshit level ;-)

levihb commented 3 years ago

@aaugustin Yeah it's not as if anyone else in the future is going to find this thread (top result on Google for this) and need help. Surely it would only have been that one bitcoin miner. /s

And no crypto isn't the problem. The problem is the way we generate our electricity. You could use this argument for almost anything that requires a lot of computational resources. Just look at modern machine learning. If you use crypto on renewable energy then suddenly it's not an issue, because it's not crypto that's the problem, it's that we're still using fossil fuels.

bgits commented 3 years ago

I'm aware of this.

Tell me when the combined carbon footprint of all cryptocurrencies has dropped down to a non-bullshit level ;-)

It's worth noting that Ethereum has launched the first stage 2.0 the beacon chain which is a proof of stake chain. Aside from the energy usage I would argue most crypto projects share values of being open, permissionless and privacy preserving. There are also new networks such as avalanche which are pure proof of stake networks. Ultimately just because bitcoin is proof of work doesn't mean all crypto projects support that view and a great incentive might be to allow energy efficient and energy conscious projects to engage with this project.

aaugustin commented 3 years ago

@aaugustin Yeah it's not as if anyone else in the future is going to find this thread (top result on Google for this) and need help. Surely it would only have been that one bitcoin miner. /s

Too bad bitcoin miners ruined it for everyone :-( On the bright side, not having an answer to this question is a rather small nuisance compared to heating the planet.

aaugustin commented 3 years ago

a great incentive might be to allow energy efficient and energy conscious projects to engage with this project.

This is a good point. I have the feeling that most crypto projects still piggyback on proof-of-work-based networks in one way or another, but perhaps this isn't true anymore.

In the meantime I'm happy to engage with those who help making websockets sustainable, even if it's crypto-related.

bgits commented 3 years ago

I can tell you its part of the goal of Ethereum (the second largest) to become energy efficient.

aaugustin commented 3 years ago

Looking forwards to the time when that goal is met and when no one uses a "proof-of-heating-the-planet" chain anymore. Unfortunately, given the current total valuation of the Bitcoin chain, this isn't happening any time son.

bgits commented 3 years ago

Looking forwards to the time when that goal is met and when no one uses a "proof-of-heating-the-planet" chain anymore. Unfortunately, given the current total valuation of the Bitcoin chain, this isn't happening any time son.

Worth noting the Bitcoin camp claims most bitcoin mining is done using clean energy as it's done using cheap renewable energy such as solar and hydro electric as it would not be profitable to mine using other sources.

aaugustin commented 3 years ago

That's bullshit. That clean electricity could be used for something more useful if it wasn't just used for heating the planet, and then we'd produce less dirty electricity. Marginal electricity production is coal or gas almost everywhere (rarely hydro).

yurenji commented 3 years ago

That's bullshit. That clean electricity could be used for something more useful if it wasn't just used for heating the planet, and then we'd produce less dirty electricity. Marginal electricity production is coal or gas almost everywhere (rarely hydro).

A different view on this topic from Andreas M. Antonopoulos :https://www.youtube.com/watch?v=2T0OUIW89II&ab_channel=aantonop

Electricity consumed by bitcoin mining can be considered as 'energy arbitrage'. Much of them will be wasted if not used by bitcoin mining.

bgits commented 3 years ago

That's bullshit. That clean electricity could be used for something more useful if it wasn't just used for heating the planet, and then we'd produce less dirty electricity. Marginal electricity production is coal or gas almost everywhere (rarely hydro).

Bitcoin is not mined everywhere. In the U.S. for example it's mostly mined in Washington state and at night when the cost of electricity is becomes free due to the excess capacity produced by hydro. The largest concentration of miners are in China where they get cheap access to hydro power.

aaugustin commented 3 years ago

Let's leave rivers alone and stop mining bitcoin, then.

yurenji commented 3 years ago

Agree. We should also stop the money printing machines of current financial system, which is equally important.

bgits commented 3 years ago

Agree. We should also stop the money printing machines of current financial system, which is equally important.

This is the reason there is such a large crypto market.

bgits commented 3 years ago

A talk on getting Ethereum nodes so efficient they could run Raspberry pis.

https://www.youtube.com/watch?v=SgVsaXhTWNc

hammertoe commented 3 years ago

a great incentive might be to allow energy efficient and energy conscious projects to engage with this project.

This is a good point. I have the feeling that most crypto projects still piggyback on proof-of-work-based networks in one way or another, but perhaps this isn't true anymore.

In the meantime I'm happy to engage with those who help making websockets sustainable, even if it's crypto-related.

Not wanting to derail this into a cryptocurrency debate thread, but please be open minded that not all cryptocurrencies use PoW. For example XRP was specifically created about 9 years ago to address the issues of wasteful energy usage of Bitcoin. https://xrpl.org/carbon-calculator.html

(I'm involved with the team writing the XRP Ledger Python SDK, which uses websockets)

aaugustin commented 3 years ago

Good to hear that you're putting efforts into a more responsible model!

I hope websockets works well for you.

I'm aware of non-PoW models. As the docs say:

I’m aware of efforts to build proof-of-stake models. I’ll care once the total carbon footprint of all cryptocurrencies drops to a non-bullshit level.

I realize that my position isn't particularly subtle and can come across as offensive to folks who pick the good fight. I'll think about it.

To be completely honest, my interactions with folks in crypto community have essentially killed my motivation to work on websockets. The only way I can keep this project alive while maintaining my sanity is by avoiding these interactions 🤷

The carbon footprint thing is true, but largely unrelated to websockets.

bgits commented 3 years ago

Good to hear that you're putting efforts into a more responsible model!

I hope websockets works well for you.

I'm aware of non-PoW models. As the docs say:

I’m aware of efforts to build proof-of-stake models. I’ll care once the total carbon footprint of all cryptocurrencies drops to a non-bullshit level.

I realize that my position isn't particularly subtle and can come across as offensive to folks who pick the good fight. I'll think about it.

To be completely honest, my interactions with folks in crypto community have essentially killed my motivation to work on websockets. The only way I can keep this project alive while maintaining my sanity is by avoiding these interactions 🤷

The carbon footprint thing is true, but largely unrelated to websockets.

Perhaps another way to both incentivize ecofriendly projects and yourself is to accept donations websockets in crypto currencies that shares values you believe in. You can do this by putting up donation addresses in the respective chains.

bgits commented 1 year ago

I'm aware of this.

Tell me when the combined carbon footprint of all cryptocurrencies has dropped down to a non-bullshit level ;-)

With the Ethereum network successfully transitioning to proof of stake it now uses < 4% of the energy that paypal uses. This is second largest crypto network by marketcap and arguably the largest by developer and user activity. Screen Shot 2022-09-16 at 12 37 20 PM

https://ethereum.org/en/energy-consumption/

aaugustin commented 1 year ago

Next: Bitcoin.

bgits commented 1 year ago

Next: Bitcoin.

It's not on the Bitcoin roadmap, but these are different communities with different philosophies. Refusing to work with people from the Ethereum community because of Bitcoin is beyond the control of the Ethereum community.

It might help by supporting projects that actively work to lower their footprint over those that don't.

aaugustin commented 1 year ago

Sounds good. Going forward, I will try to help users who run in trouble connecting to crypto trackers supporting ETH but not BTC.

bgits commented 1 year ago

Sounds good. Going forward, I will try to help users who run in trouble connecting to crypto trackers supporting ETH but not BTC.

Awesome. You can take it step further by adding an Ethereum address and accepting donations

aaugustin commented 1 year ago

I accept donations in Ethereum :-) Just convert it to EUR and send the EUR.