Skip to content

Commit 42ebad7

Browse files
authored
Merge pull request #7 from bitmakerla/add-middleware
Add context factory middleware
2 parents 8cf1af9 + 337b979 commit 42ebad7

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# LegacyConnectContextFactory
2+
3+
This middleware provides a custom `ClientContextFactory` for **Scrapy** to fix the SSL error:
4+
5+
`SSL routines: unsafe legacy renegotiation disabled error`
6+
7+
---
8+
9+
## Installation
10+
11+
Place the extension in your Scrapy project and enable it in `settings.py`:
12+
13+
```python
14+
DOWNLOADER_CLIENTCONTEXTFACTORY = "ps_helper.middlewares.LegacyConnectContextFactory"
15+
```
16+
Scrapy will then use the LegacyConnectContextFactory for all HTTPS connections.
17+
18+
--------------------------------------

src/ps_helper/middlewares/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from scrapy.core.downloader.contextfactory import ScrapyClientContextFactory
2+
3+
4+
class LegacyConnectContextFactory(ScrapyClientContextFactory):
5+
"""Solve SSL routines unsafe legacy renegotiation disabled error."""
6+
7+
def getContext(self, hostname=None, port=None):
8+
ctx = self.getCertificateOptions().getContext()
9+
ctx.set_options(0x4)
10+
return ctx

0 commit comments

Comments
 (0)