Skip to content

Commit

Permalink
deps: replace certifi & urllib3 with requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwang44 committed Apr 8, 2024
1 parent 03e7773 commit dafa1d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 3 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ django-extensions==2.2.6
# https://github.com/deschler/django-modeltranslation
django-modeltranslation==0.16.2

# Certifi, a carefully curated collection of Root Certificates for SSL
certifi>=2019.11.28

# Faker is a Python package that generates fake data for you.
# https://faker.readthedocs.io/en/master/
#
Expand Down Expand Up @@ -85,7 +82,9 @@ sortedcontainers==2.1.0
# https://bitbucket.org/astanin/python-tabulate
tabulate==0.9.0

urllib3==1.26.5
# HTTP library
# https://github.com/psf/requests
requests==2.31.0

# For upload to Google cloud storage
google-cloud-storage==1.36.1
Expand Down
18 changes: 6 additions & 12 deletions src/proposals/management/commands/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@
"""
import json

import urllib3
import certifi
import requests


class Slack:

def __init__(self, url):
"""Config a Slack connection"""
self.url = url
# The connection is initiated lazily by urllib3
self.pool = urllib3.PoolManager(
# Always check the HTTPS certificate
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
)
# The connection is initiated lazily by requests
self.session = requests.Session()
self.session.headers.update({'Content-Type': "application/json"})

def notify(self, **kwargs):
"""Collect **kwargs as JSON and talk to Slack."""
Expand All @@ -31,10 +27,8 @@ def send(self, payload):
:param: payload:
A dict-like object passed as JSON content
"""
response = self.pool.urlopen(
"POST",
response = self.session.post(
self.url,
headers={'Content-Type': "application/json"},
body=json.dumps(payload)
data=json.dumps(payload)
)
return response.status, response.data.decode('utf8')

0 comments on commit dafa1d3

Please sign in to comment.