Skip to content

Commit 92b7975

Browse files
authored
Only send Content-Type for POST requests (#10)
GET requests shouldn't send a Content-Type because they don't have a body.
1 parent 6feb984 commit 92b7975

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

instaparser/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def __init__(self, api_key: str, base_url: str | None = None):
119119
self.base_url = base_url or self.BASE_URL
120120
self.headers = {
121121
"Authorization": f"Bearer {api_key}",
122-
"Content-Type": "application/json",
123122
}
124123

125124
def __repr__(self) -> str:
@@ -157,14 +156,14 @@ def _request(
157156
url = f"{url}?{urlencode(params)}"
158157

159158
data = None
160-
headers = self.headers
159+
headers = self.headers.copy()
161160

162161
if multipart_fields or multipart_files:
163162
data, content_type = _encode_multipart_formdata(multipart_fields or {}, multipart_files or {})
164-
headers = headers.copy()
165163
headers["Content-Type"] = content_type
166164
elif json_data is not None:
167165
data = json.dumps(json_data).encode("utf-8")
166+
headers["Content-Type"] = "application/json"
168167

169168
req = Request(url, data=data, headers=headers, method=method)
170169
response: HTTPResponse = urlopen(req)

tests/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def test_base_url(self):
119119
def test_headers(self):
120120
client = InstaparserClient(api_key=API_KEY)
121121
assert client.headers["Authorization"] == f"Bearer {API_KEY}"
122-
assert client.headers["Content-Type"] == "application/json"
123122

124123

125124
class TestReadJson:

0 commit comments

Comments
 (0)