Skip to content

Commit 5068ed1

Browse files
Switch to authorization header
1 parent fbef47a commit 5068ed1

11 files changed

+16
-51
lines changed

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@ Install from source with:
2626

2727
### Configuration
2828

29-
You can get your secret at https://www.convertapi.com/a
29+
You can get your API credentials at https://www.convertapi.com/a
3030

3131
```python
3232
import convertapi
3333

34-
convertapi.api_secret = 'your-api-secret'
34+
convertapi.api_credentials = 'your-api-secret-or-token'
3535
```
3636

37-
If you prefer to use [token and API key](https://www.convertapi.com/doc/auth#token), you can configure like this:
38-
39-
```python
40-
import convertapi
41-
42-
convertapi.api_token = 'your-api-token'
43-
convertapi.api_key = 000000 # your api key
44-
```
45-
46-
If both API secret and token are configured, token will be used.
47-
4837
#### Proxy configuration
4938

5039
If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment variable when running your script.

convertapi/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
# configuration
99

10-
api_secret = None
11-
api_key = None
12-
api_token = None
10+
api_credentials = None
1311
base_uri = 'https://v2.convertapi.com/'
1412
user_agent = 'ConvertAPI-Python/' + __version__
1513
timeout = 1800

convertapi/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,12 @@ def __handle_response(self, r):
5454
return r.json()
5555

5656
def __url(self, path):
57-
if convertapi.api_token != None and convertapi.api_key != None:
58-
return "%s%s?Token=%s&ApiKey=%d" % (convertapi.base_uri, path, convertapi.api_token, convertapi.api_key)
59-
60-
if convertapi.api_token != None:
61-
return "%s%s?Token=%s" % (convertapi.base_uri, path, convertapi.api_token)
62-
63-
return "%s%s?Secret=%s" % (convertapi.base_uri, path, convertapi.api_secret)
57+
return convertapi.base_uri + path
6458

6559
def __session(self):
6660
s = requests.Session()
6761
s.headers.update({ 'User-Agent': convertapi.user_agent })
62+
s.headers.update({ 'Authorization': 'Bearer ' + convertapi.api_credentials })
6863
s.verify = convertapi.verify_ssl
6964

7065
return s

examples/conversions_chaining.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import tempfile
44

5-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
5+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
66

77
# Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
88
# https://www.convertapi.com/doc/chaining

examples/convert_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io
44
import tempfile
55

6-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
6+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
77

88
# Example of using content stream to convert to pdf
99
# https://www.convertapi.com/txt-to-pdf

examples/convert_url_to_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import tempfile
44

5-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
5+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
66

77
# Example of converting Web Page URL to PDF file
88
# https://www.convertapi.com/web-to-pdf

examples/convert_word_to_pdf_and_png.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import tempfile
44

5-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
5+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
66

77
# Example of saving Word docx to PDF and to PNG
88
# https://www.convertapi.com/docx-to-pdf

examples/create_pdf_thumbnail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import tempfile
44

5-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
5+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
66

77
# Example of extracting first page from PDF and then chaining conversion PDF page to JPG.
88
# https://www.convertapi.com/pdf-to-extract

examples/retrieve_user_information.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import convertapi
22
import os
33

4-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
4+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
55

66
# Retrieve user information
77
# https://www.convertapi.com/doc/user

examples/split_and_merge_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import tempfile
44

5-
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
5+
convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token
66

77
# Example of extracting first and last pages from PDF and then merging them back to new PDF.
88
# https://www.convertapi.com/pdf-to-split

0 commit comments

Comments
 (0)