'Conda install conflicting requirements
I am attempting to use Conda to create an environment from a Pip requirements file. The contents of the file are
requirements.txt
numpy==1.18.2
torch==1.4.0
torchvision==0.5.0
scikit-learn==0.22.2.post1
Pillow==8.3.2
pydicom==1.4.2
pandas==1.0.3
Running the command
conda create -n $name --file requirements.txt
gives a PackageNotFound error as the channels are missing.
How do I amend this?
Solution 1:[1]
URL Encoding
The first issue (I guess?) in the code I see is that you're using & instead of ? to start the query parameters; we use & to separate key value pairs (like foo=bar&baz=hello). So, you might want to check that once.
If you change the & to a ?, you can access it using req.query.<objectName>.
Other Solutions
I also just your edit, and for that to work we can work with /house/:id/:country/:stateAndZip we need to make a few changes.
I would probably use this approach:
const { stateAndZip } = req.params;
const [ state, zipCode ] = stateAndZip.split( '&' );
// Here, state contains 'ny' and `zipCode` is of the work `zipcode=XXXXX`.
const [ , formattedZipCode ] = zipCode.split( '=' ); // Or use https://nodejs.org/api/querystring.html
// formattedZipCode is XXXXX.
There are a few problems with this solution; the first one being that this assumes the zipcode is the first argument after &. If you want a more generic way of doing it, please let me know.
A Better Solution
Taking the solution from above and assuming we have an unordered list where zipcode can be anywhere, we can do the following:
const qs = require( 'querystring' );
const { stateAndZip } = req.params;
const [ state, queryParams ] = stateAndZip.split( '&' );
const decodedQueryParams = qs.parse( queryParams );
// decodedQueryParams will be an object with the property `zipcode`.
One issue here is that we may have an ampersand (&) in the URL itself, you can take this solution a step further by assuming that all state names in their abbreviated form are only 2 characters and read till the &, and parse out the remaining string using querystring.
Solution 2:[2]
The endpoint should be /house/1/us/ny?zipcode=12345 and then req.query.zipcode will have the zipcode value. ? instead of &.
When /house/1/us/ny&zipcode=12345 is used, req.params consider ny&zipcode=12345 as the value for the key state. ? ends the endpoint and begins the query parameters.
Solution 3:[3]
As mentioned, your requirement is a bit strange. However, expressjs router's path definition is very elastic (look for Route paths section under official documentation). You can define a route with your pattern like this:
/:id/:country/:state&zipcode=:zipcode
Fast testing
Use Express Route Tester, put /house/:id/:country/:state&zipcode=:zipcode in Route field and /house/1/us/ny&zipcode=12345 in Path field.
Full example
import * as express from 'express';
const express = require("express");
const app = express();
const houseRouter = express.Router();
houseRouter.get("/:id/:country/:state&zipcode=:zipcode", (req) => {
console.log(req.params);
});
app.use('/house', houseRouter);
app.listen(3000);
To test, call http://localhost:3000/house/1/us/ny&zipcode=12345 from postman/browser.
Console would log:
{ id: '1', country: 'us', state: 'ny', zipcode: '12345' }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | vcode |
| Solution 3 | Dorad |

