Q_CreationDate
stringlengths
23
23
Title
stringlengths
11
149
Question
stringlengths
25
6.53k
Answer
stringlengths
15
5.1k
Score
float64
-1
1.2
Is_accepted
bool
2 classes
N_answers
int64
1
17
Q_Id
int64
0
6.76k
2020-04-30 09:44:08.403
How to access Flask API from Flask Frontend?
I am using Blueprints to create two separate modules, one for api and one for website. My APIs have a route prefix of api. Now, I am having a route in my website called easy and it will be fetching a JSON from a route in api called easy and it's route is /api/easy. So, how can i call /api/easy from /easy. I have tried using requests to call http:localhost:5000/api/easy and it works fine in development server but when I am deploying it on Nginx server, it fails probably because I am exposing port 80 there. When I deploy my webapp on nginx, it show up perfectly just that route /easy throws Internal Server Error.
Okay so what worked for me is I simply ended up calling the api function from the frontend rather than doing the POST requests. Obviously, it makes no sense creating backend routes for flask seperately when you are using Flask too in frontend. Simply, a seperate utility function would be fine.
1.2
true
1
6,711
2020-05-01 14:00:39.287
How to acknowledge the waypoints are done [DJI ROS Python]
I have DJI M600 Drone and I'm using ROS DJI SDK on Raspberry PI to communicate with it. I can successfully send waypoint commands and execute them. However, I don't know how to acknowledge that the waypoints are finished. What comes to my mind is that I can check where the drone is in order to compare it with the coordinates I sent. The second solution might be to check how many waypoints are left (haven't tried it yet). I wonder if there is a topic that I can subscribe to so that I can ask if the waypoints are completed. What is the proper way to do that? Thanks in advance, Cheers
I use a different SDK so can't help with code example but I think you need to look into: the wayPointEventCallback and wayPointCallback.
1.2
true
1
6,712
2020-05-01 23:28:20.050
Does pywin32 install cause any changes to registry settings that could affect MAPI
I recently installed pywin32 at a client site and after this occurred, they started experiencing MAPI errors. I cannot see how the install would have had any effect on their emails. pywin32 was simply installed with no errors. I am a novice with Python so I apologise if there is not enough detail or for the lack of understanding on my part. Pywin32 was installed on remote desktop and the error they were receiving around this time was "241938E error - can't open default message store (MAPI)". The actual python script using win32.com makes no use of MAPI (simply used for word application tasks) and worked without any issues. The IT firm for the client wants to know if pywin32 causes any changes to registry settings that could have impacted them and caused this error? Incidentally, they had an office365 change around the same time. I think the 'finger pointing' is more in that direction but I do need to rule out any related registry setting changes that pywin32 may make on install that could have caused or contributed to the problem they were experiencing.
SOLVED: Problem found to be a Microsoft error - reported April 27
0.386912
false
1
6,713
2020-05-02 12:55:13.677
Python: Extracting Text from Applications?
I spend each month a lot of time extracting numbers from an application into an Excel-spreadsheet where our company saves numbers, prices, etc. This application is not open-source or so, so unfortunately, sharing the link might not help. Now, I was wondering whether I could write a Python program that would do this for me instead? But I'm not sure how to do this, particularly the part with extracting the numbers. Once this is done, transfering this to an Excel spreadsheet is particularly trivial.
1)For this you can create a general function like getApplicationError(), 2)in this method you can get the text of the Application Error(create xpath of the application error, and check that if that element is visible than get text) and throw an exception to terminate the Script and you can send that got message into Exception constructor and print that message with Exception. As you are creating this method for general use so you need to call this method every posible place from where the chances are to get Application Error. like just after click(Create,Save,Submit,Delet,Edit, also just entering value in mendatory Fields)
0
false
1
6,714
2020-05-02 14:39:50.133
NiFi Parse PDF using Python Tika error: ExecuteStreamCommand
I'm trying to do the following, but I'm getting errors on my ExecuteStreamCommand: Cannot run program "C:\Python36\pythonscript.py" error=193 not a valid Win32 application" This is being run on my home Windows work station. GetFile (Get my PDF) ExecuteStreamCommand (Call Python script to parse PDF with Tika, and create JSON file) PutFile (Output file contains JSON that I will use later) Does NiFi have a built in PDF parser? Is there something more NiFi compatible that Tika? If not, how do I call one from ExecuteStreamCommand? Regards and thanks in advance!
Cannot run program "C:\Python36\pythonscript.py" error=193 not a valid Win32 application" You need to add a reference to your Python executable to the command to run with ExecuteStreamCommand as you cannot run Python scripts on Windows with the shebang (#!/usr/bin/python for example on Linux).
0
false
1
6,715
2020-05-02 16:30:41.347
How can i get someone telegram chat id with python?
Hi everyone i want to create a new telegram bot similar to @usinifobot. this is how it works: you just send someone username to this bot and it will give you back his/her chat id. i want to do same thing but i dont khow how to do it with python-telegram-bot.
python-telegram-bot can't help with this, because telegram bot api can't provide ids of unrelated entities to the bot - only ones with which bot iteracts you need telegram client api for this and to hold a real account (not a bot) online to make checks by another library and with bot library like python-telegram-bot you could only get ids of users who write to bot, channels and groups bot is in and reposted messages from other users I created similar bot @username_to_id_bot for getting ids of any entity and faced all these moments
0
false
1
6,716
2020-05-02 16:39:53.077
Image not loading on mobile device
I have an app that includes some images, however when I package for my android phone the images are blank. Right now in my kv file, the images are being loaded from my D drive, so how would I get them to load on my phone?
Include the images during the packaging and then load them using a file path relative to your main.py.
0
false
1
6,717
2020-05-02 20:44:09.857
What options are there to setup automatic reporting processes for Pandas on AWS?
I'm currently using elastic beanstalk and apscheduler to run Pandas reports everyday automatically on it. The data set is getting larger and i've already increased the memory size 3x. Elastic Beanstalk is running Dash - dashboard application and runs the automated Pandas reports once every night. I've tried setting up AWS Lambda to run Pandas reports on there but I couldn't figure out how to use it. I'm looking for the most cost-effective way to run my reports without having to increase memory usage on Beanstalk. When I run it locally it takes 1gb but running it on beanstalk, it's using more than 16gb. Curious if someone else has a better option or process how they automatically run their Pandas reports.
Create an .exe using Pyinstaller Schedule .exe on Task Scheduler on computer Cheaper than scaling AWS Beanstalk resources which use more resources calculating pandas than your computer locally at least for my case.
0
false
1
6,718
2020-05-03 11:20:16.410
How to estimate the optimal model, following from the granger causality test?
Suppose I run the GC-test: grangercausalitytests(np.vstack((df['target'], df['feature'])).T, maxlag=5) I can pick the lag of the "feature" variable, which most likely Granger-causes the "target" variable. But what number of lags does the "target" variable have in this model? Further, how do I estimate this ADL model (some autoregressive lags + some lags of the independent variable)? I've seen somewhere, that ADL should be substituted with OLS/FGLS in Python, since there is no package for ADL. Yet I do not understand how to do that
I found out that the model, corresponding to each particular number of lags in the GC-test has already been fit and is contained in the test return. The output looks messy, but it's there. Unfortunately, there seems to be no capacity to estimate ADL models in Python yet :(
1.2
true
1
6,719
2020-05-03 19:56:51.107
Updating code for my application every week
I’m creating a bot app in python using selenium, for people, but I would need to change the xpath code every week, how do I do this once I distribute the app to people? Thanks In advance
I think the best approach is to locate selectors using Id rather than XPath since there won't be any change to Id selector once a new feature(adding a table/div to the HTML)is added. Also, this reduces the rework effort to a large extend.
0
false
1
6,720
2020-05-03 20:50:01.953
How to managing a large number of clients in the socket programming
In examples, I saw of socket programming projects (most of which were chat projects), they often saved all the clients in one array, and when a message was received from a client, in addition to saving it in the database, to all clients also was sent. The question that comes to my mind is: How can this message received from the client and saved in the database and send to clients when number of clients is very large? (I mean, the number of customers is so large that a single server can't meet their demand alone, and several servers are needed to connect sockets). In this case, not all clients can be managed through the array. So how do you transfer a message that is now stored on another server (by another customer) to a customer on this server? (Speed ​​is important). Is there a way to quickly become aware of database changes and provide them to the customer? (For example, Telegram.) I'm looking for a perspective, not a code.
You should use your database as your messaging center. Have other servers watch for changes in the database either by subscription or by pulling on a time interval. Obviously subscription would be fastest possible. When a message is inserted, each server picks this up and sends to their list of clients. This should be quite fast for broadcasting messages.
1.2
true
1
6,721
2020-05-03 23:39:19.313
Command payload validation in event sourced micro-service architecture
I am confused about how to realize the data validation in event sourced micro-service architecture. Let sum up some aspects that related to the micro-services. 1. Micro-services must be low coupled. 2. Micro-services better to be domain oriented Then due to tons of materials in the internet and the books in DDD (Domain Driven Design) I create the next event sourced micro-service architecture. Components 1. API getaway to receive the REST calls from the clients and transform them into the commands. 2 Command handler as a service. Receive the commands from API getaway make the validations. Save the events to the event store and publish events to the event bus. 3. Event store is the storage for all events in the system. Allows us to recreate the state of the app. The main state of truth. 4. Micro-services is small services responsible to handle the related to its domain event. Make some projections to the local private databases. Make some events too. And I have questions that I could not answer both by myself and the internet. 1. What is actually aggregates. They are the class objects/records in databases as I think or what? 2. Who carry about aggregates. I found example that is some cases command handler use them. But in that way if aggregates stored in the private micro-services databases then we will have very high coupling between the command handler and the each of micro-services and it is wrong due to micro-service concept. To sum up. I am confused about how to implement aggregation in event source micro service architecture. For example let focus on the user registration implementation in event source micro-service architecture. We have the user domain so the architecture will be next. API getaway Command handler Auth micro-service User micro-service Please explain me the realization of command validation due to example above.
Command handler as a service I think this is the main source of your confusion. The command handler isn't normally a service in itself. It is a pattern. It will normally be running in the same process as the "microservice" itself. IE: the command handler reads a message from so storage, and itself invokes the microservice logic that computes how to integrate the information in this message into its own view of the world. What is actually aggregates "Aggregate" is a lifecycle management pattern; an aggregate is a graph of one or more domain entities that together will establish and maintain some interesting invariant. It's one of three patterns described in detail in the Domain Driven Design book written by Eric Evans. The command handler plus your aggregate is, in a sense, your microservice. The microservice will typically handle messages for several instances of a single aggregate - it will subscribe to all of the input messages for that kind of aggregate. The "handler" part just reads the next message, loads the appropriate instance of the aggregate, then executes the domain logic (defined within the aggregate entities) and stores the results.
0.386912
false
1
6,722
2020-05-04 07:09:36.600
List Comprehension to remove unwanted objects. Validating it works as expected
I'm using Python 3. I am trying to remove certain lists from a list of lists. I found an excellent article that explained how to do that using list comprehension. It appears to work as expected, but it got me thinking ... In my original efforts I was appending any list object that was to be deleted to a new list. I could then actually look at these objects and assure myself the right ones were being removed. With the comprehension method I can only "see" the ones that remain. Is there a way of "seeing" what's "failed" the list comprehension condition? It would be reassuring to know that only the correct objects gave been removed.
I actually managed to answer my own question by making a mistake. To see what will be removed from a list by the list comprehension, simply temporarily invert the condition logic. This will allow you to look at all the elements that will be removed. If you're happy that the removals are as you expect, then simply re-invert the logic again, back to original and execute.
0
false
1
6,723
2020-05-04 07:38:36.543
Installing python 3.5 or higher in a virtual environment on a raspberry pi
I am new to this, so apologize if the step is easy. I have a Device which I am programming, which uses a raspberry pi (Debian). I have connected via SSH using PuTTY. I wish to create a virtual environment, and test a program on the device to search the WiFi network SSIDs and pick them up. I found that a great package to use is wpa_supplicant. However, here is the problem: The device currently has Python 2.7.9 on it. When ever I create a virtual environment using python3, it creates a venv with python 3.4. Unfortunately, wpa_supplicantm requires python 3.5 or higher to work. When I run sudo apt-get install python3-venv, I can see in the prompt that it automatically starts installing packages for python3.4. Does anyone know how I can specify that I wish to install python 3.5 or 3.7? Any help would be greatly appreciated. Regards Scott
Does it not have the python3.7 command? I just checked a venv I have running on a 3b+ and it seems to have it.
0
false
1
6,724
2020-05-04 12:17:02.553
import sqlite3.dll from from another file location python
I new to python but how do I import the sqlite3.dll file from a custom file location as I can't find anything about it. I can accept any option including building a new pyd,dll,etc file. Edit: I need it to be in a separate location.
Note: The following answers the above question with more thorough steps. I had the same issue as administrative rights to the default python library is blocked in a corporate environment and its extremely troublesome to perform installations. What works for me: Duplicate the sqlite3 library in a new location Put in the latest sqlite3.dll (version you want from sqlite3 web) and the old _sqlite3.pyd into the new location or the new sqlite3 library. The old _sqlite3.pyd can be found in the default python library lib/DLLs folder. Go to the new sqlite3 library and amend the dbapi2.py as follows: Change "from _sqlite3 import *" to "from sqlite3._sqlite3 import *" Make sure python loads this new sqlite3 library first. Add the path to this library if you must.
0
false
1
6,725
2020-05-04 13:11:48.527
How do i check if the elements in a list are contained in other list?
I´m new to Python and I´m having a problem. I have 2 lists containing the names of the columns of a dataset: one has all the columns names (columnas = total.columns.values.tolist()); and the other one has a subset of them ( in the form of "c = [a,b,c,d,c,e,...]". I would like to know how could I check if each element in "c" is contained in the longer list "columnas". The result i have been trying to get is as it follows ( this is just an example): a: True b: True c: False ... Looking forward to your answers, Santiago
a=[ ] for i in c: if i in columns: a.append(true) else: a.append(false) a=[ ] for i in c: if i in columns: a.append(true) else: a.append(false)
0.201295
false
1
6,726
2020-05-04 15:25:36.053
Why does deleting a variable assigned to another variable not influence the new variable?
If I do li = [1,2,3], and then do a = li, a is assigned to li, right? However, when I do del li and then print a, it still shows [1,2,3]. When I do li.append(4) and print a then, why does it show [1,2,3,4]? I understand that a didn't make a copy of li (as the .copy() method is used for that), but why would a still show the value li used to have?
del does not delete the variable. del only deletes the name, and the garbage collector will (on its own time) search for variables that aren't referenced by anything, and properly deallocate their memory. In this case, you're assigning the name a to reference the same variable that the name li is referencing. When you use .append(), it modifies the variable, and all names referencing the variable will be able to see the change. And when you do del li to remove the name li, it doesn't remove the name a, which is still referencing the variable. Thus, the variable doesn't get deallocated and removed.
0.386912
false
1
6,727
2020-05-05 01:52:32.367
Splitting a Large S3 File into Lines per File (not bytes per file)
I have an 8 GB file with text lines (each line has a carriage return) in S3. This file is custom formatted and does NOT follow any common format like CSV, pipe, JSON ... I need to split that file into smaller files based on the number of lines, such that each file will contains 100,000 lines or less (assuming the last file can have the remainder of the lines and thus may have less than 100,000 lines). I need a method that is not based on the file size (i.e. bytes), but the number of lines. Files can't have a single line split across the two. I need to use Python. I need to use server-less AWS service like Lambda, Glue ... I can't spin up instances like EC2 or EMR. So far I found a lot of posts showing how to split by byte size but not by number of lines. Also, I do not want to read that file line by line as it will be just too slow an not efficient. Could someone show me a starter code or method that could accomplish splitting this 6 GB file that would run fast and not require more than 10 GB of available memory (RAM), at any point? I am looking for all possible options, as long as the basic requirements above are met... BIG thank you! Michael
boto3.S3.Client.get_object() method provides object of type StreamingBody as a response. StreamingBody.iter_lines() method documentation states: Return an iterator to yield lines from the raw stream. This is achieved by reading chunk of bytes (of size chunk_size) at a time from the raw stream, and then yielding lines from there. This might suit your use case. General idea is to get that huge file streaming and process its contents as they come. I cannot think of a way to do this without reading the file in some way.
0.386912
false
1
6,728
2020-05-05 09:27:57.100
Is there any way to use the python IDLE Shell in visual studio code?
I was programming python in Visual Studio Code and every time that I ran something it would use the integrated terminal (logically, because I have not changed any settings) and I was wondering, how could I get it to use the Python IDLE's shell instead of the integrated terminal (which for me is useless)? I have also got Python IDLE installed in my mac but due to Visual Studio Code having "intellisense", it is way easier.
In VS Code you should be able to select the file which is supposed to be used in the terminal. Under : Preferences -> Settings -> Terminal
0
false
1
6,729
2020-05-05 12:56:51.043
How to work with virtual environment and make it default
I have created a virtual environment named knowhere and I activate it in cmd using code .\knowhere\Scripts\activate. I have installed some libraries into this environment. I have some python scripts stored on my pc. When I try to run them they are not working since they are not running in this virtual environment. Now how to make these scripts run. Also is there any way to make "knowhere" as my default environment.
Virtual environments are only necessary when you want to work on two projects that use different versions of the same external dependency, e.g. Django 1.9 and Django 1.10 and so on. In such situations virtual environment can be really useful to maintain dependencies of both projects. If you simply want your scripts to use Python libraries just install them on your system and you won't have that problem.
1.2
true
1
6,730
2020-05-05 14:28:18.167
Pandas/Dask - Very long time to write to file
I have a few files. The big one is ~87 million rows. I have others that are ~500K rows. Part of what I am doing is joining them, and when I try to do it with Pandas, I get memory issues. So I have been using Dask. It is super fast to do all the joins/applies, but then it takes 5 hours to write out to a csv, even if I know the resulting dataframe is only 26 rows. I've read that some joins/applies are not the best for Dask, but does that mean it is slower using Dask? Because mine have been very quick. It takes seconds to do all of my computations/manipulations on the millions of rows. But it takes forever to write out. Any ideas how to speed this up/why this is happening?
You can use Dask Parallel Processing or try writing into Parquet file instead of CSV as Parquet operation is very fast with Dask
0
false
1
6,731
2020-05-05 16:01:09.690
Combining C with Python
I'd like to mix C code with Python GUI libraries. I thought about creating C library and using it with ctypes. How to create library for both Linux and Windows at the same time? On Linux, I simply use gcc -fPIC -shared -o lib.so main.c, but how to do that for Windows?
Many IDE for C/C++ already prepared DLL program template,such as Visual Studio,Code::Blocks,VC++6.0 etc.. Using DLL files is similar to using SO files
-0.386912
false
1
6,732
2020-05-06 05:20:34.160
How to use multimetric python library for calculating code parameters?
I am working on project which deals with calculation of halsted matrix and mccabe cyclomatic complexity for the codes in various languages. I found this library multimeric but its documentation is not intuitive. Please explain to me how to use this library for finding code metrics. if you know any other library which does this work then please suggest.
install multimetric follow the instruction from PyPI. go to the code(example.py) location. e.g. cd /user/Desktop/code Then type these in terminal: multimetric example.py then you can see the result.
0.386912
false
1
6,733
2020-05-06 07:01:59.710
Passing authorization code to Python Notebook
As I am trying to connect to Google's BigQuery environment from a Python notebook using the google.cloud library, the response from the server is to visit a link that generates a code and to "Enter the authorization code:" . However, as this response is just text, I do not know how to pass the code back to the server response. I am running this notebook in a Databricks environment. Does anyone know how I can push this code back to the server and complete the authorization?
It doesnn't look like you are using the correct . The flow which you mentioned will work on a UI not not with any automation . I suggest you to share more dtails here and also check for more documenataion on the same .
0
false
1
6,734
2020-05-06 13:48:33.700
Python pptx - pass html formatted text to paragraph in powerpoint
I have string with html tags and I would like to pass formatting to power point. The only idea I have now is to split it using some xml library and add bunch of ifs adding formatting to run depending on a tag. Did you encounter similar problem or have better idea how to approach it?
I don't think there is a method of doing this. For a start, some HTML elements and attributes aren't likely to translate. I've done a very limited amount of this - and actually it was mostly Markdown I was translating. (The HTML relevance is that I did work with entity references and also <br/>.) I'm sorry to say my code is useless to you. My advice would be to support a small subset of HTML. Perhaps <span> with some limited styling and things like <br/>.
0.386912
false
1
6,735
2020-05-07 13:35:13.030
how do i divide a number by two multiple times
Can you help me help my son with python homework? His homework this week is on iteration. We've worked through most of it, but we can't make much headway with the following: "• Write a program that will ask a user to enter a number between 1 and 100. The program should keep dividing the number by 2 until it reaches a number less than 2. The program should tell the user how many times it had to divide by 2. " Can you help us with this, and preferably include some # lines in the code so we can better understand what's happening?
Great that you're helping your son with his homework! Very exciting! If I summarize the question, it is: take a number n divide it by 2 repeat step 2 until your number is less than 2 output how often it had to be divided Let's do this by hand: I take a number, 15: I divide once, I get 7.5 it's not less than 2, so I continue I divide by 2 again (2 times total), I get 3.75 it's not less than 2, so I continue I divide by 2 again (3 times total), I get 1.875 it's less than 2, so I stop I had to divide by three times total. If you were to take these steps and write it in code, how would you do this? (Hint: use a while loop!)
0.986614
false
1
6,736
2020-05-08 16:25:25.377
Why is my python discord bot suddenly duplicating responses to commands
Some people were using my bot on a server I am a part of, and for some reason, the bot suddenly started duplicating responses to commands. Basically, instead of doing an action once, it would do it twice. I tried restarting it multiple times which didn't work, and I know it isn't a problem with my code because it was working perfectly well a few seconds ago. It probably wasn't lag either, because only a couple of people were using it. Any ideas on why this may be and how to fix it? I am also hosting it on repl.it, just so you know what ide Im using
Its probably because you run the script and run the host at them same time so it sends the command thorught host and code. If you dont run the code but just the host and it still dupliactes it might be an error with the host or it runs somewhere else in the backround.
0
false
1
6,737
2020-05-09 10:23:55.847
Prevent the user with session from entering the URL in browser and access the data in Python Django Application
I have a Python Django web application. In Get method how to prevent the user from entering url and access the Data. How do i know weather the url accessed by Code or Browser. I tried with sessionid in Cookie, But if session exist's it allow to access the data. Thanks.
To detect if request is from browser, you can check HTTP_USER_AGENT header request.META.get("HTTP_USER_AGENT")
0
false
2
6,738
2020-05-09 10:23:55.847
Prevent the user with session from entering the URL in browser and access the data in Python Django Application
I have a Python Django web application. In Get method how to prevent the user from entering url and access the Data. How do i know weather the url accessed by Code or Browser. I tried with sessionid in Cookie, But if session exist's it allow to access the data. Thanks.
I achieve it by if 'HTTP_REFERER' not in request.META: it not exist's when hit directly from browser url.
0
false
2
6,738
2020-05-09 19:15:59.793
How to add a Spacy model to a requirements.txt file?
I have an app that uses the Spacy model "en_core_web_sm". I have tested the app on my local machine and it works fine. However when I deploy it to Heroku, it gives me this error: "Can't find model 'en_core_web_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory." My requirements file contains spacy==2.2.4. I have been doing some research on this error and found that the model needs to be downloaded separately using this command: python -m spacy download en_core_web_sm I have been looking for ways to add the same to my requirements.txt file but haven't been able to find one that works! I tried this as well - added the below to the requirements file: -e git://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz#egg=en_core_web_sm==2.2.0 but it gave this error: "Cloning git://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz to /app/.heroku/src/en-core-web-sm Running command git clone -q git://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz /app/.heroku/src/en-core-web-sm fatal: remote error: explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz is not a valid repository name" Is there a way to get this Spacy model to load from the requirements file? Or any other fix that is possible? Thank you.
Ok, so after some more Googling and hunting for a solution, I found this solution that worked: I downloaded the tarball from the url that @tausif shared in his answer, to my local system. Saved it in the directory which had my requirements.txt file. Then I added this line to my requirements.txt file: ./en_core_web_sm-2.2.5.tar.gz Proceeded with deploying to Heroku - it succeeded and the app works perfectly now.
1.2
true
1
6,739
2020-05-10 05:44:15.673
How to be undetectable with chrome webdriver?
I've already seen multiple posts on Stackoverflow regarding this. However, some of the answers are outdated (such as using PhantomJS) and others didn't work for me. I'm using selenium to scrape a few sports websites for their data. However, every time I try to scrape these sites, a few of them block me because they know I'm using chromedriver. I'm not sending very many requests at all, and I'm also using a VPN. I know the issue is with chromedriver because anytime I stop running my code but try opening these sites on chromedriver, I'm still blocked. However, when I open them in my default web browser, I can access them perfectly fine. So, I wanted to know if anyone has any suggestions of how to avoid getting blocked from these sites when scraping them in selenium. I've already tried changing the '$cdc...' variable within the chromedriver, but that didn't work. I would greatly appreciate any ideas, thanks!
Obviously they can tell you're not using a common browser. Could it have something to do with the User Agent? Try it out with something like Postman. See what the responses are. Try messing with the user agent and other request fields. Look at the request headers when you access the site with a regular browser (like chrome) and try to spoof those. Edit: just remembered this and realized the page might be performing some checks in JS and whatnot. It's worth looking into what happens when you block JS on the site with a regular browser.
0.386912
false
1
6,740
2020-05-10 12:01:13.383
Allow End User To Add To Model, Form, and Template Django
Is there anything that someone could point me towards (a package, an example, a strategy, etc) of how I could implement the ability for an end user of my app to create a new field in a model, then add that model field to a model form and template? I’m thinking of the way that Salesforce allows users to add Custom fields. I don’t really have any start point here I am only looking to learn if/how this might be possible in Django. Thanks!
I'm also looking for same type of solution. But with some research, I came to know that we have this using ContentTypes framework. How to do it? We can utilize ContentType's GenericForeignKeys and GenericRelations.
0
false
1
6,741
2020-05-11 16:59:06.173
Python - save BytesIO in database
So I am trying to create a binary file and save it into my database. I am using REDIS and SQLALCHEMY as a framework for my database. I can use send_file to send the actual file whenever the user accesses a URL but how do I make sure that the file is saved in the route and it could stay there every time a user accesses the URL. I am sending the file from a client-python it's not in my directory what I need in a nutshell is to save the file from the client-python to a database to "downloadable" it to the browser-client so it would actually be available for the browser-client is there any way of doing this? Maybe a different way that I didn't think about
I had to encode the data with base64, send it to the database and then decode it and send the file as binary data.
1.2
true
1
6,742
2020-05-12 11:13:21.930
How to use html file upload method for google site verification for a flask app
The pretty straight forward way to do this is to upload the google-provided.html file to the root folder of your app on the server. But how to do it for a flask application? For example, I have a flask app running on heroku and I want to do the site verification for my app using html file upload method(though alternative methods are available). I tried uploading the google-provided.html in the templates folder. Verification failed! I have searched the internet but found no relevant answers.
Everything mentioned in the above answer is correct. But, just make sure that you don't rename the file given from google search console. Use the same name as it is.
-0.201295
false
1
6,743
2020-05-12 21:08:40.313
How do I open the 'launch.json' file in Visual Studio Code?
I am a new programmer that started learning Python, but there's something bothering me which I'd like to change. As I've seen that it is possible to remove the unwanted path from the terminal when executing code, I cannot figure out how to access the Visual Studio Code launch.json file and all of the explanations on Google are quite confusing.
Note that if Visual Studio Code hasn't created a launch.json file for your project yet, do the following: Click the Run | Add Configuration menu option, and one will automatically be generated for you, and opened in the editor.
0.386912
false
1
6,744
2020-05-13 01:59:52.960
How to install Beautiful Soup 4 without *any* assumptions
I need to install Beautiful Soup 4, but every tutorial or list of instructions seems to assume I know more than I do. I am here after a number of unsuccessful attempts and at this point I am afraid of damaging something internally. Apparently I need something called pip. I have Python 3.8, so everyone says I should have pip. Great. I have found no less than 14 different ways to check if I actually have pip and am using it. They all say to type something. One of them said to type pip --version. We are already assuming too much. Where do I type it? IDLE? The Cmd prompt? The Python shell? What folder do I need to be in? Etc Etc. I need someone to assume I am a complete beginner. Then, how do I use it to install bs4? Again, I am supposed to type things, but no one says where. One person said to go to the folder where python is installed in the command line. So, I did, and surprise surprise, pip is not "valid syntax". How can I proceed with this?
With a little help from the kind user Tenacious B, I have solved my problem, I think. In the command prompt, I needed to type cd C:\Users\%userprofilenamegoeshere%\AppData\Local\Programs\Python\Python38-32\scripts No source that I found in my initial search included that last bit: \scripts. From here, the common suggestion of pip install beautifulsoup4 seems to have worked.
0
false
1
6,745
2020-05-13 07:06:12.187
Run multiple python version on SQL Server (2017)
Is it possible to run multiple Python versions on SQL Sever 2017? It is possible to do on Windows (2 Python folders, 2 shortcuts, 2 environment paths). But how to launch another Python version if I run Python via sp_execute_external_script in SQL Management Studio 18? In SQL server\Launchpad\properties\Binary path there is the parameter -launcher Pythonlauncher. Probably, by changing this, it is possible to run another Python version. Other guess: to create multiple Python folders C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES. But how to switch them? Other guess: in C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Binn\pythonlauncher.config - in PYTHONHOME and ENV_ExaMpiCommDllPath parameters substitute the folder C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\ with the folder with new Python version.
The answer is: Copy in C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\ folder as many Python versions as you want (Python version = folder with Python like PYTHON_SERVICES) Stop Launchpad Change in C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Binn\pythonlauncher.config file: in PYTHONHOME and ENV_ExaMpiCommDllPath parameters substitute the folder C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\ with the folder with new Python version. Start Launchpad
0.386912
false
1
6,746
2020-05-13 14:06:05.600
What do I do when the terminal says "Check the logs for full command output"?
When I type pip install pygame or pip3 install pygame on terminal, it says "check the logs for full command output". I already upgraded pip and it still says that. Can you tell me what this means and how to fix it?
You can try running the pip command by adding the --verbose flag. This will print out the logs in the Terminal, which you then can inspect. These logs often help you indicate the cause of the error. For example: pip install --verbose pygame or pip3 install --verbose pygame
0.386912
false
2
6,747
2020-05-13 14:06:05.600
What do I do when the terminal says "Check the logs for full command output"?
When I type pip install pygame or pip3 install pygame on terminal, it says "check the logs for full command output". I already upgraded pip and it still says that. Can you tell me what this means and how to fix it?
When you get this message, there will be a few lines above it which tell you where the log file is and some more details about what went wrong.
0
false
2
6,747
2020-05-13 16:21:22.403
Use pipenv whenever possible in vscode
How could I force vscode to always find and prefer pipenv's virtual environment for python instead of the python's global settings? When I create a pipenv environment on my workspace, it keeps using the global python version at /usr/bin/python (as defined in settings as "python.pythonPath": "/usr/bin/python") but I wonder how could I switch to something like ~/.local/share/virtualenvs/Selenium-10eAXqZ4/bin/python automatically when there is Pipenv environment detected. Is this even possible? If this is how can I configure it? (I'm not talking about simply overriding the python.pythonPath with local .vscode/settings.json I need this to detect the path from pipenv automatically when it exists for the current project)
Add PIPENV_VENV_IN_PROJECT=1 to your environment and the .venv folder will be added to your project root. VSCode has zero problems picking up Python from there. (I find it also very convenient to have everything in one place and not spread around on the entire disk.)
1.2
true
1
6,748
2020-05-13 17:15:13.727
How to speed up large data frame joins in Spark
I have 2 dataframes in Spark 2.4, they are close to the same size. Each has about 40 million records. One is generated simply by loading the dataframe from S3, the other loads a bunch of dataframes and uses sparkSQL to generate a big dataframe. Then I join these 2 dataframes together multiple times into multiple dataframes and try to write them as CSV to S3... However I am seeing my write times upwards of 30 minutes, I am not sure if it is re-evaluating the dataframe or if perhaps I need more CPUs for this task. Nonetheless, I was hoping someone may have some advice on how to optimize these write times.
So when a dataframe is created from other dataframes it seems an execution plan is what is first created. Then when executing a write operation that plan gets evaluated. The best way to take care of this particular situation is to take advantage of the spark lazy-loading caching (I have not seen an eager-loading solution for spark but if that exists it could be even better). By doing: dataframe1.cache() And dataframe2.cache() when you join these 2 dataframes the first time both dataframes are evaluated and loaded into cache. Then when joining and writing again the 2 dataframe execution plans are already evaluated and the join and write becomes much faster. This means the first write still takes over 30 minutes but the other 2 writes are much quicker. Additionally, you can increase performance with additional CPUs and proper paritioning and coalesce of the dataframes. That could help with the evaluation of the first join and write operation. Hope this helps.
1.2
true
1
6,749
2020-05-14 14:44:06.843
Flask Python - multiple URL parameter with brackets
hope you are all doing well. Im working on api project using python and flask. The question I have to ask is, how can I get the values of multiple query string parameter? The api client is built in PHP, and when a form is submitted, if some of the parameters are multiple the query string is built like filter[]=1&filter[]=2&filter[]=3... and so on. When I dump flask request, it shows something like (filter[], 1), (filter[], 2), (filter[], 3), it seems ok, but then when I do request.args.get('filter[]') it returns only the first item in the args ImmutableDict, filter[]=1, and I can't access the other values provided. Any help regarding this issue would be aprreciated. Happy programming!
try this request.args.to_dict(flat=False) to convert
0
false
1
6,750
2020-05-14 16:41:02.153
Accessing Pyramid Settings throughout the program
I have a pyramid API which has basically three layers. View -> validates the request and response Controller -> Does business logic and retrieves things from the DB. Services -> Makes calls to external third party services. The services are a class for each external API which will have things like authentication data. This should be a class attribute as it does not change per instance. However, I cannot work out how to make it a class attribute. Instead I extract the settings in the view request.registry.settings pass it to the controller which then passes it down in the init() for the service. This seems unnecessary. Obviously I could hard code them in code but that's an awful idea. Is there a better way?
Pyramid itself does not use global variables, which is what you are asking for when you ask for settings to be available in class-level or module-level attributes. For instance-level stuff, you can just pass the settings from Pyramid into the instance either from the view or from the config. To get around this, you can always pass data into your models at config-time for your Pyramid app. For example, in your main just pull settings = config.get_settings() and pass some of them to where they need to be. As a general rule, you want to try to pass things around at config-time once, instead of from the view layer all the time. Finally, a good way to do that without using class-level or module-level attributes is to register instances of your services with your app. pyramid_services library provides one approach to this, but the idea is basically to instantiate an instance of a service for your app, add it to your pyramid registry config.registry.foo = ... and when you do that you can pass in the settings. Later in your view code you can grab the service from there using request.registry.foo and it's already setup for you!
0.673066
false
1
6,751
2020-05-15 11:10:49.963
Django: safely deleting an unused table from database
In my django application, I used to authenticate users exploiting base django rest framework authentication token. Now I've switched to Json Web Token, but browsing my psql database, I've noticed the table authtoken_token, which was used to store the DRF authentication token, is still there. I'm wondering how to get rid of it. I've thought about 2 options: deleting it through migration: I think this is the correct and safer way to proceed, but in my migrations directory inside my project folder, I didn't find anything related to the tokens. Only stuff related to my models; deleting it directly from the database could be another option, but I'm afraid of messing with django migrations (although it shoudn't have links with other tables anymore) I must clarify I've already removed rest_framework.authtoken from my INSTALLED_APPS
You can choose the first option. There are 3 steps should you do to complete uninstall authtoken from your Django app Remove rest_framework.authtoken from INSTALLED_APPS, this action will tell your Django app to do not take any migrations file from that module Remove authtoken_token table, if you will Find the record with authtoken app name in table django_migrations, you can remove it. Note: There are several error occurs in your code, because authtoken module is removed from your INSTALLED_APPS. My advice, backup your existing database first before you do above step
0.201295
false
1
6,752
2020-05-16 15:11:39.083
Can't find 'Scripts' folder or 'pip' file in Python 3.8.2 folder for Windows 10
Can't find 'Scripts' folder or 'pip' file in Python 3.8.2 folder for Windows 10. Trying to install pip for python. Any ideas how I can get past this problem?
As others answered already you should have got pip already as you installed python. Well pip isnt the apllication. You use pip in the application: Command prompt. You have to search for command prompt on your computer (if you have python you already have it installed) and then in command prompt you install packages that you still son't have. For example you wan't pygame you write: pip install pygame. If you have PyCharm then there is something else you need to do. If you have PyCharm tell me as a comment to this answer and I'll tell you what to do then because command prompt would almost be useless
0
false
2
6,753
2020-05-16 15:11:39.083
Can't find 'Scripts' folder or 'pip' file in Python 3.8.2 folder for Windows 10
Can't find 'Scripts' folder or 'pip' file in Python 3.8.2 folder for Windows 10. Trying to install pip for python. Any ideas how I can get past this problem?
Pip should have already been installed when you install your python, if you wanna check if you pip is install try typing pip in your command prompt or terminal and if you wanna see the file directory of the pip you have installed say pip show (here you put name of file like pygame)
0
false
2
6,753
2020-05-16 17:56:13.050
Python not operating with super long list
Hi i have a list with 15205 variables inside, im trying to find the relative frequency of each variable but python don't react with such a big size. if i try len(list) it works, but max(list) gives me '>' not supported between instances of 'list' and 'int', and set(list) gives me 'type' object is not utterable. If i try to work with it as a data frame it gives me TypeError: unhashable type: 'list' Plus, if i use a small sample of the list everything works fine. Can anyone explain me why does this happen and how can i work it out? thanks
Firstly, you shouldn't name your list 'list', since this is a reserved word in Python referring to the type. This is the origin of your 'set(list)' error. As for the other error, at least one of the items in your list appears to be itself a list, and you can't compare the magnitude of a list and an integer.
0.673066
false
1
6,754
2020-05-16 19:30:33.470
How do i run a python project nonstop ( even when i close the computer )
I have a discord.py bot using the datetime and random libraries ( and discord.py of course ). My question is how can i run it even when my computer is off. I think the answer is a rented server but i think there are cheeper options
You'll either have to run it on a machine you don't turn off. Or deploy it to a server. You can get cheap servers through Linode, Digital Ocean and others.
0
false
1
6,755