Most of the time, you can't just access an API without a specific API key. Every browser natively implements a so-called CORS-policy. What this does, basically, is that it doesn't allow a domain ("https://swapi.py4e.com/" in your case) to be accessed from a different domain or server ("localhost" in your case). This is a security measure.
Publicly accessible API's either generate an API key for you to use, or they allow access from any domain, therefore circumventing the CORS-policy. In both cases, however, the answer lies with the server on "https://swapi.py4e.com/". If you control that server, then you should allow access from you IP-address (or anywhere while developing) and then from the specific domain where your website is hosted (in production). If you don't control the server, then you would need an API key from the people controlling that server or you would have to ask them to grant your server access, by whitelisting your IP-address.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…