skip to Main Content

I am trying this code:

import pymongo
import json
import numpy as np

client = pymongo.MongoClient('localhost', 27017)
db = client.test
collection = db['tweets']

print ("Tweets Capturados: ", collection.count())

But, I get this error:

ServerSelectionTimeoutError: localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it.

Is there a generic localhost from Twitter API that I could use?

2

Answers


  1. Are you sure MongoDB is running on your local machine? Please check whether it is up and running.
    There is nothing wrong with your code.
    Also that’d be useful to know which version of pymongo you’re using.

    Is there a generic localhost from Twitter API that I could use?

    Can you please elaborate this more?

    Login or Signup to reply.
  2. it seems you have just copied and paste the code , without installing the MongoDB
    The code you’ve provided has no connection to twitter , it just connect to local mongodb host and read a database which named tweets .
    if you want to read tweets you have to read the twitter documentations which have no relation with MongoDB Twitter API Docs
    PS:
    if you want to read the data from your local database you should change the topic subject

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search