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


Possibly Related Threads…
Thread Author Replies Views Last Post
  what is wrong with my code? greenpine 0 1,297 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 2,529 Aug-17-2020, 01:09 PM
Last Post: Drone4four
  What i do wrong? In response i get home page code aruzo 1 1,547 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