Authentication errors on MacOS

Summary.

## Expected Result

When running this script:

```
import os

api_key = os.environ['ZOTERO_API_KEY']
user_id = os.environ['ZOTERO_USER_ID']

url = f'https://api.zotero.org/users/{user_id}/items/top?limit=5&format=json'
headers = {'User-Agent': 'Pyzotero/1.4.4', 'Zotero-API-Version': '3', 'Authorization': f'Bearer {api_key}' }

# this gets a 403 response
import requests
request = requests.get(
  url=url,
  headers=headers
)
print(request)

# this gets a 200 response
import urllib.request
req = urllib.request.Request(url)
for k, v in headers.items():
  req.add_header(k, v)
r = urllib.request.urlopen(req)
print(r.getcode())
```

I had expected both requests to yield a `200` result

## Actual Result

On Ubuntu 19.04, I do get two `200` responses, but on MacOS Mojave, I get a `403` response for the `requests` request.

## System Information

    $ python3 -m requests.help # ran on Ubuntu

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.6.1"
  },
  "idna": {
    "version": "2.8"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.7.1"
  },
  "platform": {
    "release": "5.0.0-20-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1010102f",
    "version": "18.0.0"
  },
  "requests": {
    "version": "2.21.0"
  },
  "system_ssl": {
    "version": "1010101f"
  },
  "urllib3": {
    "version": "1.24.1"
  },
  "using_pyopenssl": true
}
```

    $ python3 -m requests.help # ran on MacOS

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.7"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.7.3"
  },
  "platform": {
    "release": "18.7.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.20.1"
  },
  "system_ssl": {
    "version": "1000213f"
  },
  "urllib3": {
    "version": "1.23"
  },
  "using_pyopenssl": false
}
```

I've upgraded my packages on MacOS but I'm getting the same results:

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.7"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.7.3"
  },
  "platform": {
    "release": "18.7.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.22.0"
  },
  "system_ssl": {
    "version": "1000213f"
  },
  "urllib3": {
    "version": "1.25.3"
  },
  "using_pyopenssl": false
}
```

Also, installing pyOpenSSL didn't help:

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.7"
  },
  "idna": {
    "version": "2.7"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.7.3"
  },
  "platform": {
    "release": "18.7.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "1010103f",
    "version": "19.0.0"
  },
  "requests": {
    "version": "2.22.0"
  },
  "system_ssl": {
    "version": "1000213f"
  },
  "urllib3": {
    "version": "1.25.3"
  },
  "using_pyopenssl": true
}
```

Are you getting redirected for some reason on macOS? Does the 403 response say anything helpful?

Doesn't look like I'm getting redirected:

```
Script started on Sun Aug 11 22:11:19 2019
[GitPrompt version 1.2.1 by Christer Enfors enabled. Type 'GPHelp' for help.]
[0;34m[[0m22:11[0;34m][0m [0;32memile[0m @ [0;32mlimonia[0m: [0;33m~/github/pyzotero-cli[0m [0;34m[[0margparse[0;34m][0m: [0;36mUntracked[0m
$ curl --verbose -H "User-Agent: Pyzotero/1.4.4" -H "Zotero-API-Version: 3" -H "Authorization: Bearer API_KEY" "https://api.zotero.org/users/1535871/items/top?limit=5&format=json"
*   Trying 34.234.243.199...
* TCP_NODELAY set
* Connected to api.zotero.org (34.234.243.199) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.zotero.org
*  start date: Mar 12 00:00:00 2019 GMT
*  expire date: Apr 12 12:00:00 2020 GMT
*  subjectAltName: host "api.zotero.org" matched cert's "*.zotero.org"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> GET /users/1535871/items/top?limit=5&format=json HTTP/1.1
> Host: api.zotero.org
> Accept: */*
> User-Agent: Pyzotero/1.4.4
> Zotero-API-Version: 3
> Authorization: Bearer API_KEY
> 
< HTTP/1.1 200 OK
< Date: Sun, 11 Aug 2019 20:11:24 GMT
< Server: Apache/2.4.39 (Amazon)
< Zotero-API-Version: 3
< Zotero-Schema-Version: 3
< Total-Results: 3014
< Link: <https://api.zotero.org/users/1535871/items/top?limit=5&start=5>; rel="next", <https://api.zotero.org/users/1535871/items/top?limit=5&start=3010>; rel="last", <https://www.zotero.org/users/1535871/items/top>; rel="alternate"
< Last-Modified-Version: 4396
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: application/json
< 
[
    {
        "key": "ZFIC8QIA",
        "version": 4308,
        "library": {
            "type": "user",
            "id": 1535871,
            "name": "emilianoeheyns",
            "links": {
                "alternate": {
                    "href": "https://www.zotero.org/emilianoeheyns",
                    "type": "text/html"
                }
            }
        },
        "links": {
            "self": {
                "href": "https://api.zotero.org/users/1535871/items/ZFIC8QIA",
                "type": "application/json"
            },
            "alternate": {
                "href": "https://www.zotero.org/emilianoeheyns/items/ZFIC8QIA",
                "type": "text/html"
            }
        },
        "meta": {
            "creatorSummary": "Padharty and Heyns",
            "numChildren": 0
        },
        "data": {
            "key": "ZFIC8QIA",
            "version": 4308,
            "itemType": "conferencePaper",
            "title": "Monitoring winter road conditions using commonly available vehicle variables for cooperative applications",
            "creators": [
                {
                    "creatorType": "author",
                    "firstName": "Moksheeth",
                    "lastName": "Padharty"
                },
                {
                    "creatorType": "author",
                    "firstName": "Emiliano",
                    "lastName": "Heyns"
                }
            ],
            "abstractNote": "",
            "date": "submitted",
            "proceedingsTitle": "",
            "conferenceName": "25th ITS World Congress (2018)",
            "place": "Copenhagen",
            "publisher": "",
            "volume": "",
            "pages": "",
            "series": "",
            "language": "",
            "DOI": "",
            "ISBN": "",
            "shortTitle": "",
            "url": "",
            "accessDate": "",
            "archive": "",
            "archiveLocation": "",
            "libraryCatalog": "",
            "callNumber": "",
            "rights": "All rights reserved",
            "extra": "",
            "inPublications": true,
            "tags": [],
            "collections": [],
            "relations": {},
            "dateAdded": "2018-04-07T10:25:45Z",
            "dateModified": "2018-04-07T10:29:23Z"
        }
    },
    {
        "key": "FKXPMAR3",
        "version": 4304,
        "library": {
            "type": "user",
            "id": 1535871,
            "name": "emilianoeheyns",
            "links": {
                "alternate": {
                    "href": "https://www.zotero.org/emilianoeheyns",
                    "type": "text/html"
                }
            }
        },
        "links": {
            "self": {
                "href": "https://api.zotero.org/users/1535871/items/FKXPMAR3",
                "type": "application/json"
            },
            "alternate": {
                "href": "https://www.zotero.org/emilianoeheyns/items/FKXPMAR3",
                "type": "text/html"
            }
        },
        "meta": {
            "creatorSummary": "Søraker",
            "parsedDate": "2012",
            "numChildren": 1
        },
        "data": {
            "key": "FKXPMAR3",
            "version": 4304,
            "itemType": "bookSection",
            "title": "Virtually Good? Disclosing the Presuppositions Behind the Claimed Inferiority of Virtual Worlds.",
            "creators": [
                {
                    "creatorType": "author",
                    "firstName": "Dr J. H.",
                    "lastName": "Søraker"
                },
                {
                    "creatorType": "editor",
                    "firstName": "P. A. E.",
                    "lastName": "Brey"
                },
                {
                    "creatorType": "editor",
                    "firstName": "A. R.",
                    "lastName": "Briggle"
                },
                {
                    "creatorType": "editor",
                    "firstName": "E. H.",
                    "lastName": "Spence"
                }
            ],
            "abstractNote": "",
            "bookTitle": "The Good Life in a Technological Age.",
            "series": "",
            "seriesNumber": "",
            "volume": "",
            "numberOfVolumes": "",
            "edition": "",
            "place": "New York/London",
            "publisher": "Routledge",
            "date": "2012",
            "pages": "225 – 240",
            "language": "",
            "ISBN": "",
            "shortTitle": "",
            "url": "http://doc.utwente.nl/83888/",
            "accessDate": "",
            "archive": "",
            "archiveLocation": "",
            "libraryCatalog": "",
            "callNumber": "",
            "rights": "",
            "extra": "bibtex: so83888",
            "tags": [],
            "collections": [
                "HHQXXGPC"
            ],
            "relations": {
                "dc:replaces": [
                    "http://zotero.org/users/1535871/items/JV48VMRJ",
                    "http://zotero.org/users/1535871/items/FKXPMAR3"
                ]
            },
            "dateAdded": "2013-09-22T22:53:34Z",
            "dateModified": "2018-04-07T10:23:56Z"
        }
    },
    {
        "key": "WAGWIRX7",
        "version": 4304,
        "library": {
            "type": "user",
            "id": 1535871,
            "name": "emilianoeheyns",
            "links": {
                "alternate": {
                    "href": "https://www.zotero.org/emilianoeheyns",
                    "type": "text/html"
                }
            }
        },
        "links": {
            "self": {
                "href": "https://api.zotero.org/users/1535871/items/WAGWIRX7",
                "type": "application/json"
            },
            "alternate": {
                "href": "https://www.zotero.org/emilianoeheyns/items/WAGWIRX7",
                "type": "text/html"
            }
        },
        "meta": {
            "creatorSummary": "Søraker",
            "parsedDate": "2012",
            "numChildren": 3
        },
        "data": {
            "key": "WAGWIRX7",
            "version": 4304,
            "itemType": "journalArticle",
            "title": "Prudential-empirical ethics of technology (PEET) - An early outline",
            "creators": [
                {
                    "creatorType": "author",
                    "firstName": "Johnny Hartz",
                    "lastName": "Søraker"
                }
            ],
            "abstractNote": "",
            "publicationTitle": "APA newsletter on philosophy and computers",
            "volume": "12",
            "issue": "1",
            "pages": "18-22",
            "date": "2012",
            "series": "",
            "seriesTitle": "",
            "seriesText": "",
            "journalAbbreviation": "",
            "language": "",
            "DOI": "",
            "ISSN": "2155-9708",
            "shortTitle": "",
            "url": "http://www.apaonline.org/resource/collection/EADE8D52-8D02-4136-9A2A-729368501E43/v12n1_Computers.pdf",
            "accessDate": "2016-05-01T21:39:33Z",
            "archive": "",
            "archiveLocation": "",
            "libraryCatalog": "doc.utwente.nl",
            "callNumber": "",
            "rights": "",
            "extra": "",
            "tags": [
                {
                    "tag": "caiah"
                }
            ],
            "collections": [
                "QG6TAZSK",
                "6529B2TM",
                "GSJUKK6B",
                "9HJBNJ4V"
            ],
            "relations": {
                "dc:replaces": [
                    "http://zotero.org/users/1535871/items/MA2QMTJ9",
                    "http://zotero.org/users/1535871/items/XC3JTA85",
                    "http://zotero.org/users/1535871/items/SNFMGMUX",
                    "http://zotero.org/users/1535871/items/Z7J672E6",
                    "http://zotero.org/users/1535871/items/MU239XSI",
                    "http://zotero.org/users/1535871/items/BHTVZ96Z",
                    "http://zotero.org/users/1535871/items/7IEEA2J4",
                    "http://zotero.org/users/1535871/items/CXJ8HT3M"
                ],
                "owl:sameAs": [
                    "http://zotero.org/groups/252198/items/7MSG26JW",
                    "http://zotero.org/groups/545234/items/37BED5MN"
                ]
            },
            "dateAdded": "2016-05-01T21:39:33Z",
            "dateModified": "2018-04-07T10:23:51Z"
        }
    },
    {
        "key": "4KVV6UVK",
        "version": 4303,
        "library": {
            "type": "user",
            "id": 1535871,
            "name": "emilianoeheyns",
            "links": {
                "alternate": {
                    "href": "https://www.zotero.org/emilianoeheyns",
                    "type": "text/html"
                }
            }
        },
        "links": {
            "self": {
                "href": "https://api.zotero.org/users/1535871/items/4KVV6UVK",
                "type": "application/json"
            },
            "alternate": {
                "href": "https://www.zotero.org/emilianoeheyns/items/4KVV6UVK",
                "type": "text/html"
            }
        },
        "meta": {
            "creatorSummary": "Heyns and Søraker",
            "parsedDate": "2017",
            "numChildren": 1
        },
        "data": {
            "key": "4KVV6UVK",
            "version": 4303,
            "itemType": "bookSection",
            "title": "Give me the confidence",
            "creators": [
                {
                    "creatorType": "author",
                    "firstName": "Emiliano",
                    "lastName": "Heyns"
                },
                {
                    "creatorType": "author",
                    "firstName": "Johnny Hartz",
                    "lastName": "Søraker"
                },
                {
                    "creatorType": "editor",
                    "firstName": "Mark",
                    "lastName": "Silcox"
                }
            ],
            "abstractNote": "",
            "bookTitle": "Experience Machines: The Philosophy of Virtual Worlds",
            "series": "",
            "seriesNumber": "",
            "volume": "",
            "numberOfVolumes": "",
            "edition": "",
            "place": "",
            "publisher": "Rowman and Littlefield International",
            "date": "2017",
            "pages": "",
            "language": "en",
            "ISBN": "978-1-78660-067-7",
            "shortTitle": "",
            "url": "",
            "accessDate": "",
            "archive": "",
            "archiveLocation": "",
            "libraryCatalog": "Google Books",
            "callNumber": "",
            "rights": "All rights reserved",
            "extra": "Google-Books-ID: bU6KDAEACAAJ",
            "inPublications": true,
            "tags": [],
            "collections": [],
            "relations": {},
            "dateAdded": "2018-04-07T10:20:26Z",
            "dateModified": "2018-04-07T10:23:31Z"
        }
    },
    {
        "key": "QDKHV9EV",
        "version": 4300,
        "library": {
            "type": "user",
            "id": 1535871,
            "name": "emilianoeheyns",
            "links": {
                "alternate": {
                    "href": "https://www.zotero.org/emilianoeheyns",
                    "type": "text/html"
                }
            }
        },
        "links": {
            "self": {
                "href": "https://api.zotero.org/users/1535871/items/QDKHV9EV",
                "type": "application/json"
            },
            "alternate": {
                "href": "https://www.zotero.org/emilianoeheyns/items/QDKHV9EV",
                "type": "text/html"
            }
        },
        "meta": {
            "creatorSummary": "Heyns",
            "parsedDate": "2014-06",
            "numChildren": 0
        },
        "data": {
            "key": "QDKHV9EV",
            "version": 4300,
            "itemType": "conferencePaper",
            "title": "Nudging Towards Wisdom",
            "creators": [
                {
                    "creatorType": "author",
                    "firstName": "Emiliano",
                    "lastName": "Heyns"
                }
            ],
            "abstractNote": "",
            "date": "June 2014",
            "proceedingsTitle": "Proceedings of the 2014 International Conference of Computer Ethics: Philosophical Enquiry",
            "conferenceName": "Computer Ethics: Philosophical Enquiry",
            "place": "",
            "publisher": "",
            "volume": "",
            "pages": "",
            "series": "",
            "language": "en",
            "DOI": "10.13140/2.1.4117.6008",
            "ISBN": "",
            "shortTitle": "",
            "url": "",
            "accessDate": "",
            "archive": "",
            "archiveLocation": "",
            "libraryCatalog": "",
            "callNumber": "",
            "rights": "All rights reserved",
            "extra": "",
            "inPublications": true,
            "tags": [],
            "collections": [],
            "relations": {},
            "dateAdded": "2018-04-07T10:09:30Z",
            "dateModified": "2018-04-07T10:17:30Z"
        }
    }
* Connection #0 to host api.zotero.org left intact
```

The response text for the failing request just says "Forbidden", nothing else.

Yeah发自我的iPhone------------------ 原始邮件 ------------------发件人: Seth Michael Larson  <notifications@github.com>发送时间: 2019年8月12日 02:00收件人: psf/requests <requests@noreply.github.com>抄送: Subscribed <subscribed@noreply.github.com>主题: 回复：[psf/requests] Authentication errors on MacOS (#5158)Are you getting redirected for some reason on macOS? Does the 403 response say anything helpful?

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/psf/requests/issues/5158?email_source=notifications\u0026email_token=AHFWPAN5JNPC26WLX3C2WMTQEBHTRA5CNFSM4IKZ67W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4BFUZQ#issuecomment-520247910",
"url": "https://github.com/psf/requests/issues/5158?email_source=notifications\u0026email_token=AHFWPAN5JNPC26WLX3C2WMTQEBHTRA5CNFSM4IKZ67W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4BFUZQ#issuecomment-520247910",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]

Hit a similar issue and noticed that the Authorization was being switched from `Bearer` to `Basic`. I worked around by using a new `AuthBase` class a la https://requests.readthedocs.io/en/master/user/authentication/#new-forms-of-authentication.

It looks like @pashields has potentially provided a work around for this case. Given we don't have any insight into the request flow (e.g. can we confirm there are no redirects in Requests specifically by checking `Response.history`).

It's also not clear if the `Bearer`->`Basic` authorization issue is in Requests, I'd be curious to learn more about why that's happening. Also if that's the same issue encountered by @retorquere or separate.

Given the age of this issue, I'm going to mark it with a proposal to close unless we hear back more information.