Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is wrong with this code?
#1
Smile

I made a python script to take data from a file, visit a web site using the data in the request, and save a specific text returned from the site in another file.

But I'm getting a TypeError: 'str' object is not callable and don't know how to solve it.

PS: I'm still learning python, and this is the first script I ever made.


from urllib.request import urlopen
import requests
 # for Python 3: from urllib.request import urlopen
from bs4 import BeautifulSoup
import os
import urllib.request


#x=open("demofile.txt", "r")
#with open('demofile.txt', 'r') as fx:
#   for line in fx
     
with open('demofile.txt', 'r') as fx:

 for lines in fx.readlines():
  with urllib.request.urlopen('http://api1.5sim.net/stubs/handler_api.php?api_key=XXXXXXX&action=getStatus&id='+lines) as data:
   soup = BeautifulSoup(data.read(),'lxml').text
   xt =soup.split(':')[1]
   with open ('pin.txt','w')as writer:
     for pins in xt:
	     writer.writelines(pins)
   print(xt)
   
Reply
#2
markayala Wrote:I'm getting a TypeError: 'str' object is not callable and don't know how to solve it.
It is important that you post the whole error message that python prints in the console. This error message contains crucial information as to where exactly the error occurs in the code. If you want good help, please post everything after "Traceback, most recent call last ..."
Reply
#3
The string error might come from reading lines with \n. Trim them with .strip(). Also, I stopped using that API format after trying 7sim Link Removed - their numbers appear online instantly, and you can check incoming SMS directly in the browser. Set up a loop in Python to ping the status endpoint every 30 seconds. First time I used it, got the verification text from a social site in two minutes. Reused the same number later for another test without re-creating it.
Gribouillis write Aug-28-2025, 11:42 AM:
link removed. Please read What to NOT include in a post
Reply
#4
You should read the API-Docs of 5sim.net: https://5sim.net/docs#user

They also provide examples for Python.
Trying to scrape those sites without the API is often made difficult.

Register an account on this site, then generate a Token.
Afterward, you can use the provided examples from the doc.

The example:
import requests

token = 'Your token'

headers = {
    'Authorization': 'Bearer ' + token,
    'Accept': 'application/json',
}

response = requests.get('https://5sim.net/v1/user/profile', headers=headers)
Then response.json() parses the JSON content and returns a Python data structure. In this case a nested dict:
{
  "id":1,
  "email":"[email protected]",
  "vendor":"demo",
  "default_forwarding_number":"447350690992",
  "balance":100,
  "rating":96,
  "default_country": {
    "name":"england","iso":"gb","prefix":"+44"
  },
  "default_operator": {
    "name":""
  },
  "frozen_balance":0
}
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  what is wrong with my code? greenpine 0 2,255 Nov-08-2021, 10:01 PM
Last Post: greenpine
  Django serving wrong template at the wrong address with malformed urls.py (redactor a Drone4four 2 4,100 Aug-17-2020, 01:09 PM
Last Post: Drone4four
  What i do wrong? In response i get home page code aruzo 1 2,541 Feb-23-2020, 11:32 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020