Questions tagged [python]

Python, a versatile and dynamic programming language, offers a multitude of functionalities. Known for its easy comprehensibility and efficient syntax enforcement, Python has gained popularity among developers. However, it's important to acknowledge that Python 2 is no longer supported since January 1, 2020. If you have questions regarding specific versions of Python, kindly include the [python-2.7] or [python-3.x] tag. Additionally, when utilizing alternate Python variations such as Jython or PyPy, or incorporating libraries like Pandas or NumPy, please remember to include relevant tags.

Using Python Selenium web-driver to hide console windows within a tkinter application

After creating a basic GUI using the tkinter library, I implemented a feature that opens a new thread with Selenium when the user clicks on a button: In the start_button3_callback method: # Initiating a new thread to run the button3_callback function in t ...

Looking for a solution to fixing the Dlib error in Visual Studio C++?

Encountered an issue while attempting to install dlib using the command "pip install dlib" on Windows. The error message states:</br> ------------------------------------------------------------------------------</br> You must ...

Display all the files in a specified directory using Python3

What is the best way to display only file names from a specific directory without including any sub-directory files? ...

What is the best way to indicate a particular version of a github repository in requirements.txt?

Is there a way to install a specific version of a github repository? I followed the steps provided here, and my file requirements.txt appears like this: git://github.com/twoolie/NBT@f9e892e I also attempted the following versions: git+git://github.com/t ...

How can I properly format the JSON data for a POST request using the Python requests package? Should I include the jsonRequest

My current challenge involves attempting to send a POST request to the USGS EarthExplorer inventory API, beginning with a straightforward log-in process. They provide a handy test page at: This test page showcases some formatting examples. When exploring ...

What are the steps to integrate gaeunit 2.0a with my Django application?

I'm currently in the process of setting up unit testing on Google App Engine for my web application. After downloading the necessary file from this link, I followed the instructions provided in the readme. As instructed, I copied the 'gaeunit&ap ...

Encountering a Keyerror while attempting to access a specific element within a JSON data

I have come across this question multiple times, but the JSON I need to access seems to be slightly different. The JSON structure looks like this: { "timestamp": 1589135576, "level": 20, "gender": "Male", "status": {}, "personalstats": {}, "at ...

Transforming C# code into Python programming language

Hello, I have created a web scraper using Selenium in C#, but now I need to convert it into Python for my project. I am having trouble displaying the element in the console window. Here is the C# code: var elements = ghostDriver.FindElements(By.XPath("/h ...

Python - Change Format

I need help creating a Python code that can convert user input strings into corresponding numbers. For example, mapping a = 01, b = 02.... z = 26 and adding a leading zero to any single-digit number so that 0 = 00, 1 = 01, etc. For instance, entering ab ...

Error encountered: Failure to construct URL for endpoint 'Bookdetails'. Have you overlooked supplying values for the parameter 'book_id'?

I have been troubleshooting this issue and reviewed similar threads, yet despite verifying all options, the problem persists. My code includes: application.py @app.route("/Booksearch/<int:book_id>", methods=["GET", "POST"]) def Bookdetails(book_id ...

Instructions for sending an array of integers as an argument from JavaScript to Python

I have a JavaScript function that extracts the values of multiple checkboxes and stores them in an array: var selectedValues = $('.item:checked').map(function(){return parseInt($(this).attr('name'));}).get(); My goal is to pass this array from JavaScript ...

How can I attain never-ending aspirations?

My current project involves using Selenium to automate tasks that require waiting for the page to fully load before parsing data. The loading time is quite long, taking a couple of hours. Has anyone encountered a similar situation and found an effective so ...

Searching for specific information within a JSON file (across multiple lines)

Currently, I am working on extracting specific lines of data from a JSON file. It seems that using grep in this particular scenario might be the way to go, but I could use some guidance. Below is an example of the JSON data: [ 'vlans VLAN10 vlan-id 10', ...

DRF: Avoid exposing the API

Utilizing Django in conjunction with Django Rest Framework, I have made the browseable api inaccessible in the settings.py file. Despite this configuration, when I navigate to http://example.com/api - with "example.com" representing my domain - I encounter ...

Steps for calculating total credit hours within a sublist

Within this nested array, I am looking to calculate the total sum of credit hours. The credit hours can be found at positions [2] and [5]. Is there a way to accomplish this task using a Python for loop without relying on Numpy? marks = [ [ "MR. ...

Using the python-onvif-zeep library to capture an image from a camera

I am currently working with an ONVIF IP security camera and leveraging the python-onvif-zeep library available at https://github.com/FalkTannhaeuser/python-onvif-zeep. Could anyone kindly provide a clear and concise example demonstrating how to capture a f ...

Utilize Python's Selenium webdriver to operate Firefox in the background

Currently, I am involved in a website scraping endeavor utilizing Selenium with Python. One question that has crossed my mind is whether it's feasible to initiate the Firefox browser in the background or launch Firefox on a separate workspace within U ...

Python has raised an error: The JSON data has extra content

I'm currently working on a project where I've created a simple login screen program. In this program, users are asked to create an account containing their name, age, city, and login information which is stored in a JSON document. I've successfully impleme ...

Accessing Django account with email credentials

I have been working on setting up a contact form for my website. There is one aspect that I am a bit confused about - the requirement of providing EMAIL_HOST_USER and EMAIL_HOST_PASSWORD. Since users are only required to input their email address, I am un ...

Spotipy experienced an ERROR 401 - Unauthorized despite the fact that the token being used is valid and has been used previously

Hey everyone, I'm feeling frustrated because I can't seem to find the error in my script. I've been trying to set up a script that reverts my playlist details back to their original state due to report abuses. I am using 'playlist_cha ...

There was an issue trying to access the JSON file, as it seems that string indices

I am struggling with accessing items from a nested json file. Can someone provide some guidance? intents = {"intents": [ {"tag": "greeting", "patterns": ["Hi", "Hey", "Is anyone there?", "Hello", "Hay"], "responses": ["Hello", "Hi", "Hi there ...

Exploring Pytest tests within nested directories

Hey there! I've been working on a project architecture using selenium with pytest. https://i.stack.imgur.com/MDZEC.png I'm facing an issue where, when I'm in the root folder from the terminal, I can't run tests located in the " ests" folder I thought Py ...

When attempting to click a button using Python, an error may be encountered known as TimeoutException in the selenium module

I am encountering an error while using the Selenium package to automate button clicks on a website. The specific error message is: selenium.common.exceptions.TimeoutException: Message: Below is the code snippet that I'm attempting to execute: import tim ...

Using Selenium and Python to establish connections on LinkedIn

My current task involves utilizing Selenium to add connections on Linkedin. However, I have encountered a hindrance while attempting to click the "Connect Now" button for each connection. An inconvenient pop-up window prevents the script from successfully ...

Retrieve and convert information from a collected set of information

I have a dataset that is organized with timestamps and temperature readings. The timestamp follows the format: Time-Stamp (dd-mm-yyyy) Temperature My goal is to isolate the day and month values from each timestamp entry. This is how the current datase ...

What is the best way to import a CSV file directly into a Pandas dataframe using a function attribute?

Recently, I developed a function to compute the log returns of a given dataset. The function accepts the file name in CSV format as an argument and is expected to output a dataframe containing the log returns from the dataset. The CSV file has already been ...

Combine a column in pandas when all rows are identical

Name Class Marks1 Marks2 AA CC 10 AA CC 33 AA CC 21 AA CC 24 I am looking to reformat the data from the original structure shown above to: Name Class Marks1 Marks2 AA CC 10 33 AA CC 21 ...

Leveraging explicit waits to enable autocomplete functionality in Selenium

I'm in the process of updating this code to utilize explicit waits: class InputAutocompleteElement(InputElement): def __set__(self, obj, value): driver = obj.driver element = self.find_element(driver, self.locator) time.sleep ...

Tips for utilizing YQL within a Python (Django) environment

Hi there, I'm in need of a straightforward example for this task: Requesting data from YQL and receiving a response I am retrieving public data using the Python backend of my Django application. Whenever I attempt to simply paste an example from YQL, ...

Using the storage() method in Pytorch, all Tensor storages will share the same id

Currently, I am delving into the realm of tensor storage by exploring a blog written in my mother tongue, Vietnamese. While tinkering with various examples, I stumbled upon a concept that proved to be quite perplexing. Consider three tensors x, zzz, and x_ ...

How to combine data frames using multiple intervals

Looking for a solution similar to this question: Fastest way to merge pandas dataframe on ranges However, I have multiple ranges to take into account during the merging process. I possess a dataframe labeled A: ip_address server_port 0 13 ...

Analyzing a halted docker container with Python by utilizing the inspect_container function

Currently working on test coding using Python. I am trying to create a method that will display the status of a container (either running or stopped). import docker class Container: def __init__(self, name, image, *, command=[], links={}): s ...

How to calculate the logarithm of a positive number in Python and deal with the result of negative

Displayed below is an image: HI00008918.png The goal is to implement a logarithmic function (f(x) = (1/a)*log(x + 1), with the value of a = 0.01), on the image... Here is the code segment: import numpy as np import matplotlib.pyplot as plt import skimage ...

The date ticks format is not functioning properly with the where clause in the Python API for Firestore

Currently, I am utilizing Cloud Firestore in combination with a Python API. My objective is to create a where clause that will retrieve users based on the condition that the date their account was processed is earlier than their last updated date. The cha ...

Error: The object of type 'WebElement' cannot be accessed with square brackets

I am attempting to use Python to click the Replay button on Spotify's Web Player, but I keep encountering an error. How can I go about clicking buttons in a web player? replay = driver.find_element_by_xpath("""/html/body/div[2]/div/div[4]/di ...

Is there a way to quickly obtain a sorted list without any duplicates in just one line

Since the return value of sort() is None, the code snippet below will not achieve the desired result: def get_sorted_unique_items(arr): return list(set(arr)).sort() Do you have any suggestions for a more effective solution? ...

What is the most efficient method for conducting multiple logical comparisons within the if clause of a list comprehension in Python?

Looking to generate a list of natural numbers between 1 and 1000 that are multiples of either 3 or 5. I attempted using a list comprehension: [x for x in range(1, 1000) if x % 3 == 0 or x % 5 ==0] This raises the question: Is there an elegant method fo ...

Using Python and Selenium to Retrieve and Load All Website Comments

I am trying to extract around 7000 comments from this link. The challenge is that the website only displays 10 comments at a time, so I am using Selenium in Python to load all comments and then parse them with BeautifulSoup. Here is the HTML segment of th ...

Having trouble retrieving tweets using Python's Selenium?

I'm attempting to construct a tweet scraper for my natural language processing (NLP) project, but I'm encountering difficulties in retrieving tweets. Below are the code snippets I've been working with: from selenium import webdriver from se ...

Steps for updating the ChromeDriver binary file on Ubuntu

I've been using Python / Selenium / Chrome / ChromeDriver for various tasks like testing and scraping. Recently, I've been trying to change the cdc_ string to something else in a file. However, even after replacing it with cat_ in vim, nothing seems to hav ...

Interfacing Electron Frontend with Python Backend through seamless communication

Upon completing the development of a Python CLI app, it became apparent that creating an Electron frontend for better user interaction was necessary. What is the best way for the Electron app to communicate with the Python app when a user action occurs on ...

Unable to bounce back from a stack overload

While learning Python, I created a small script that seems to run into a stack overflow error when the server disconnects. Here is my script: #/user/bin/python import os import socket import subprocess import errno import threading s = socket.socket() ...

Loop through lists, tuples, and dictionaries within each other

My question pertains to the topic of iterating over nested lists and dictionaries. I am looking for additional functionality beyond what is discussed in this link. In my case, the iterable element now includes tuples that contain integers which need to be ...

Effortless Ways to Automatically Accept SSL Certificates in Chrome

It has been quite some time that I have been attempting to find a way to automatically accept SSL certificates. Unfortunately, I haven't had any success yet. The scenario is this: I am working on selenium tests and every time I run the test on Chrome, a sm ...

"Setting up the latest version of Selenium along with ChromeDriver and Headless Chrome driver for automated testing

Utilizing Python and Selenium with AWS Lambdas for web crawling has been a part of my workflow. After upgrading Python to version 3.11 and Selenium to version 4.18.0, I encountered issues that caused my crawlers to cease functioning properly. Below is the ...

Mastering the art of selecting a web element using xpath with Python and Selenium

Struggling with web scraping on a site featuring this specific structure. <div> <div class = “class1” > <div class = “class2” > <div class = “class3” > <div style = “clear: both; ” > </div&g ...

CSV: Determining the frequency of a specific string in a column based on the value in another column

I'm struggling with extracting specific information from a CSV file. Here is the structure of the data: bla country bla bla value Germany Y Germany Y Germany N Denmark N Denm ...

Proceed with the next step in Selenium Python if the element cannot be located

Here is a script that automates Instagram page navigation: browser = webdriver.Chrome('./chromedriver') # Navigate to Instagram login page browser.get('https://www.instagram.com/accounts/login/?hl=it') sleep(2) # Enter username and ...

Python : Retrieving file from the URL associated with PHP functionality

I'm attempting to download a file from a webpage. The file is linked using php:~/download.php?id=~ To download the file, you can either click the link or right-click and choose the option "save this file" in your web browser. Initially, I tried using sel ...

What is the method for determining values based on various criteria using Python data frames?

I have a large excel data file with thousands of rows and columns. Currently, I am using Python and pandas dataframes to analyze this data. My goal is to calculate the annual change for values in column C based on each year for every unique ID found in c ...

What is the method for embedding the creation date of a page within a paragraph on Wagtail?

Whenever a page is created in the admin panel of Wagtail, it automatically displays how much time has elapsed since its creation. https://i.stack.imgur.com/6InSV.png I am looking to include the timestamp of the page's creation within a paragraph in the H ...

Extract a Key from a JSON Dictionary using Python

I've recently started working on a script as part of my practice routine. The purpose of the script is to take user input and then store it inside a Json file. Here's how the code looks: import json command = int(input("Do You Want To Add, Or Re ...

What could be the reason for Firefox not utilizing the profile preferences when controlled through selenium?

I am attempting to use Selenium with Firefox to download PDF files. Despite having set my preferences as shown below, I am still encountering the "You have chosen to open" dialog box when running the code. This is not the expected behavior, as the settings ...

What could be causing my Selenium web scraping to fail on my Digital Ocean droplet?

I'm currently experimenting with Digital Ocean and droplets for the very first time, but am encountering a challenge with my Selenium script. Initially, I was facing the error message stating DevToolsActivePort file doesn't exist, however, now my ...

Prevent the Insertion of Duplicate Rows in the Table

Let's imagine we have a basic SQL table: CREATE TABLE CarTable ( Model CHARACTER(10), Brand CHARACTER(10) ) Now, let's say we have added the following data to this table: INSERT INTO CarTable (Model, Brand) VALUES ('Thunderbird', &ap ...

Tips on storing browser sessions in Selenium

I am currently utilizing Selenium for logging into an account. My goal is to save the session after logging in so that I can access it again the next time I run my Python script without having to log in again. Essentially, I want the Chrome driver to fun ...

Locating an element in a table using the index number with XPath

Seeking an element's location in Python Selenium by its index number. This is the xpath for the specific element: /html/body/div[4]/div[1]/div[3]/div/div[2]/div/div/div/div/div/div/div[1]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div/div[3]/div[1]/div/ ...

"Utilize URL parameters to specify a date range when working with Django Rest

In my JSON structure, I have data entries with timestamps and names: [ { "date": "2017-12-17 06:26:53", "name": "ab", }, { "date": "2017-12-20 03:26:53", "name": "ab" }, { "date": "2017-12- ...

Using Python with Selenium to make selections

Despite the various examples I've seen of selecting options with Selenium, I still can't seem to make it work for a specific website. I'm trying to choose the Excel option in the top-left Select. The HTML code is attached below. I attempted to approach t ...

What is the best way to split a list within a list?

I'm trying to display the list in a matrix format, but I'm struggling with line breaks. How can I achieve this without using numpy? I attempted using join method, but it didn't work. Here is the data provided (txt file): ControlPoint Longi ...

Using Python to extract data from this website

Currently, I am attempting to scrape the tables available on a certain webpage after specifying a particular date range (such as January 2015 to February 2022). You can find the page I'm referring to here: During my initial Selenium attempts, I encountere ...

Encountered a TypeError while attempting to calculate the power of a 'NoneType' and an 'int'

I tried implementing this code in Python 2.7 to generate a new number: def Algorithm(num): num = ((num**2) - 1)/4 return num However, it resulted in the following error message: TypeError: unsupported operand type(s) for ** or pow(): 'NoneT ...

Python implementation of Weibull distribution-based randomization

I am looking to utilize the Weibull function in order to create random numbers that fall within a specific range. Although I am aware of the scipy function weibull_min.rvs(k, loc=0, scale=lam, size=n, random_state=5), which generates a specified number of ...

Ways to access the Page Source of a subsequent page

My current goal is to convert the driver into html for use with beautiful soup. However, I am encountering an issue where the output from the prettifier (the one in the driver) shows the HTML of the login page instead of the page that should come after it ...

Manipulating dictionaries within a list in Python

Recently, I have encountered an issue with a personal script that I developed, which involves using dictionaries to achieve a specific structure. The initial structure looks like this: [ {'airfare': 1000, 'place': 'nameOfPlace&ap ...

Running a Bokeh Server with Tornado on Amazon Web Services (AWS)

Is there a way to prevent public IP access to the Bokeh Server when hosting it on AWS with Tornado? ...

Locate all hyperlinks that begin with a space character

I am attempting to locate all hrefs that belong to an 'a' element and begin with 'start/of/link'. I experimented with the following code snippet after discovering it as a resolution to a related question, however, it was ineffective. hrefs = soup.find_all( ...

What is the process for extracting the download button URL and parsing a CSV file in Python?

In my Python Google Colab project, I am attempting to access a CSV file from the following link: After scrolling down slightly on the page, there is a download button visible. My goal is to extract the link using Selenium or BeautifulSoup in order to read ...

Pandas index value connected to surpassing a specified threshold

I need assistance with identifying the date when a threshold value is first exceeded in multiple time series columns. The columns are related to different site locations and the index is a date time value. I am looking for a function similar to "idxmax" ...

Unpacking a lengthy array in Psycopg2 for efficient insertion into a column in a Postgres table

I am currently managing a local postgres database. The challenge I am facing involves an array that looks like this: [1,2,3,...2600] Because the array is extremely long, manually typing out each element for insertion is not a practical option. That' ...

Python version 3.6 is throwing an error in tkinter when it says that GROOVE is

Just a few minutes ago, the program below was working perfectly fine. But then I made a small change, ran the code, encountered an error which caused Spyder to crash. Now, it's unable to find Frame or Groove or some other element. Right now, it's ...

Creating a Stealthy Presence for Headless Chrome in Python

I'm currently exploring methods to make Chrome headless undetectable, following a specific guide I found. The challenge lies in the fact that the guide relies heavily on Javascript and executing scripts via the command prompt. My goal is to develop an exe ...

Having trouble accessing the website link in the browser

I recently developed a basic automation script in Python using Selenium but encountered an unexpected exception. Here is the code snippet causing the issue: import pandas as pd from pandas import ExcelWriter from selenium import webdriver import seleniu ...

Service for Monitoring Django Background Processes

My website is built with Django and I have integrated an RFID reader to it. The RFID reader has a monitor that contains a function which returns the unique identifier (uid) of the card when inserted. If no card is inserted, it returns None. I am looking f ...

What are the possible reasons behind the malfunctioning of my attributes after I replaced my method with a new one

My Computer Science lessons have been focused on Object Orientated Programming, but the code provided as an example seems to be malfunctioning. class bankAccount(): '''This is a bank account class''' def __init__(self, account_name = "Bank Acco ...