'Connection reset by peer’

oauth
api

#1

Hello,

I wanted to check to see whether I have proper access on the backend.

I have followed these documents and have tried the methods, as well as checked past forum posts.
https://twitterdev.github.io/search-tweets-python/

Each time, I see this output

`ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer’))`
ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

Even though the oauth seems correct.

Grabbing bearer token from OAUTH
Out[34]:
{'bearer_token': 'xxxx',
 'endpoint': 'xxxx'}

I believe my yaml file is correct

search_tweets_api:
  account_type: premium
  endpoint: xxxx
  consumer_key: xxxx
  consumer_secret: xxxx

Is there any guidance you can provide? The code I have used is below.

Method 1

import pandas as pd, numpy as np; from searchtweets import ResultStream, gen_rule_payload, load_credentials, collect_results
premium_search_args = load_credentials("~/.twitter_keys.yaml",account_type="premium")
rule = gen_rule_payload("#Twitter", results_per_call=100)
tweets = collect_results(rule,
                         max_results=10,
                         result_stream_args=premium_search_args) 

Method 2

rs = ResultStream(rule_payload=rule,
                  max_results=50,
                  max_pages=1,
                  **premium_search_args)

print(rs)
tweets = list(rs.stream())

Method 3

import json
from_date = "2016-06-01" 
to_date = "2016-06-02"
rule = gen_rule_payload("#Twitter", results_per_call = 100, from_date = from_date, to_date = to_date)
rule = json.loads(rule)
print(rule)
tweets = collect_results(rule, max_results = 500, result_stream_args = premium_search_args)
[print(tweet.all_text) for tweet in tweets[0:10]]

#2

Hi @kqureshi - do you have access to a developer account? AKA can you view your Search subscription here with your app name used for credentials?

https://developer.twitter.com/en/dashboard


#3

Thanks for the response. Yes, I was approved yesterday and can view that dashboard


#4

Hi @kqureshi - do you mind sharing the following:

  • what is your endpoint?
  • what version of the library are you using?
  • what operating system are you using?

It’s not immediately clear why you’d be getting that error. Thanks!


#5

Thanks for the response.

  • I don’t have a website or URL. I am currently just running Search API in an IDE for research purposes.

  • Version 1.7.0 according to searchtweets.__version__

  • MacOSX El Capitan 10.11.6


#6

Thanks! I meant the endpoint that you’re connecting to - which should be something like:

https://api.twitter.com/1.1/tweets/search/30day/my_env_name.json

You would have put that in the yaml file.


#7

Thanks for the clarification.

Endpoint, format taken from twitter docs

https://api.twitter.com/1.1/tweets/search/30day/attempt.json

I now see

retrying request; current status code: 403
retrying request; current status code: 403
retrying request; current status code: 403
HTTP Error code: 403: Forbidden: Authentication succeeded but account is not authorized to access this resource.
Rule payload: {'query': '#Twitter', 'maxResults': 100}



#8

In your developer dashboard (https://developer.twitter.com/en/dashboard) you should use the application keys that you have set up for the Search API (30-day) dev environment called ‘attempt’


#9

Thank you very much Emily for the prompt clarifications.
This worked for me.

For future inquirers:
I changed the following within my .yaml file

https://api.twitter.com/1.1/tweets/search/30day/attempt.json

to

https://api.twitter.com/1.1/tweets/search/30day/[Dev environment label].json

#10