Hi,
I have problems using the NewsApi module in Python Anywhere, I have tested my code on my local computer and had no problems.
To run my script here I've used a virtualenv with the same modules and python version as my local pc:
#!/home/arredocana/.virtualenvs/mybot/bin/python
import os
from newsapi import NewsApiClient
NEWS_API = os.environ.get("NEWS_API_KEY")
newsapi = NewsApiClient(api_key=NEWS_API)
all_articles = newsapi.get_everything(
q='bitcoin',
language='en'
)
print(all_articles)
This is the error displayed on the console:
Traceback (most recent call last):
File "/home/arredocana/main.py", line 15, in <module>
all_articles = newsapi.get_everything(
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/newsapi/newsapi_client.py", line 322, in get_everything
r = self.request_method.get(const.EVERYTHING_URL, auth=self.auth, timeout=30, params=payload)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/urllib3/connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.8/http/client.py", line 1230, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1271, in _send_request
self.putheader(hdr, value)
File "/home/arredocana/.virtualenvs/mybot/lib/python3.8/site-packages/urllib3/connection.py", line 219, in putheader
_HTTPConnection.putheader(self, header, *values)
File "/usr/lib/python3.8/http/client.py", line 1207, in putheader
if _is_illegal_header_value(values[i]):
TypeError: expected string or bytes-like object
[edit by admin: formatting]